swift_truth
swift_truth
MModular
Created by swift_truth on 11/3/2023 in #questions
Cannot run a Fibonacci sequence function in the Playground.
I just copied a simple Python function to a playground cell, and the code won't run, and gives me the error:
expression failed to parse (no further compiler diagnostics)
The function is a run-of-the-mill array based Fibonacci sequence generator. Why does this not run? (I am very new to Mojo and the playground)
fn fib1(n): # I tried both def and fn
if n == 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fibs = [0, 1]
for i in range(2, n):
fibs.append(fibs[-1] + fibs[-2])
return fibs
fn fib1(n): # I tried both def and fn
if n == 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fibs = [0, 1]
for i in range(2, n):
fibs.append(fibs[-1] + fibs[-2])
return fibs
1 replies