0

Trying to make a little Fibonacci game where the user guesses a set amount of steps. I'm trying to make a functioning Fibonacci generator to make the lists to refer to later, but nothing is showing up. I'm sure I'm returning the values. What am I doing wrong?

""" Core Fibonacci Code

a = int(input("How many steps of fibonacci would you like? "))

def fibonacci(counter):
    a = 0
    b = 1
    count = 2
    print (a)
    print (b)
    fib = [0, 1]
    while (counter > count):
        c = a + b
        print (c)
        a = b
        b = c
        count += 1

fibonacci(a)

"""

def fibonacci(counter):
    a = 0
    b = 1
    count = 2
    print (a)
    print (b)
    fib_list.append = a
    fib_list.append = b
    while (counter > count):
        c = a + b
        fib_list.append = c
        a = b
        b = c
        count += 1

def homescreen():
    print = ("Which gamemode would you like to play?")
    print = ("EASY - 10 Steps")
    print = ("MEDIUM - 25 Steps")
    print = ("HARD - 50 Steps")
    request = input("")
    if request is "Easy" or "easy":
        z = 10
    elif request is "Medium" or "medium":
        z = 25
    elif request is "Hard" or "hard":
        z = 50
    return z


homescreen()
fibonacci(z)
print (fib_list)
3
  • 3
    What's with the print =? Commented May 16, 2018 at 13:59
  • If you're returning something from a function, then, while you use that function, you need to use a variable to store that returned value. For eg, z = homescreen() Commented May 16, 2018 at 14:03
  • well your fib_list is in the in the wrong scope. either declare it outside your fibonacci(counter) function or return it and get it with fib_list = fibonacci(z) Commented May 16, 2018 at 14:04

1 Answer 1

1

Use print("Which gamemode would you like to play?") and not print=.

You use such format when your returning something from the called function. eg:

def foo():
        #Something
       return y
 x=foo()

Note : Use the function append(), dont use lib_list.append=a. Also declare lib_list outside the function fibonacci() as you're mentioning it in the function call outside of the function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.