0

Edit - All fixed thank you

fib=[0,1]
for i in range(0,700):
    fib.append(fib[len(fib)-2]+fib[len(fib)-1])
    print(fib[len(fib)-1])
print('Do you want a range of numbers or single?')
answer=input()
if answer=='single':
    print('Which number?')
    number=int(input())
    fib[number]
elif answer=='range':
    print('From:')
    firstNumber=int(input())
    print('To:')
    secondNumber=int(input())
    fib[firstNumber:secondNumber]

I have been trying to create a Fibonacci sequence in python which allows you to choose either which number to show or what range of numbers to show (script above). However when i run the script it runs fine at the start, i get to the part when you enter the number you want (either a single number, or the to and from numbers) but when i do nothing happens and the script ends. I am very new to python (coming from html and css, and i CBA right now to code this in HTML xD). Could anyone help me?

4
  • 4
    put the code in the question not an image Commented Aug 30, 2016 at 15:23
  • 1
    You seem to think that you put the for-loop in your code in a function. Put your for-loop in a function. Commented Aug 30, 2016 at 15:31
  • You obviously know how print works, why don't you use it? Commented Aug 30, 2016 at 15:31
  • you do not print out the result of fib[number] or fib[firstNumber:secondNumber] so it doesn't get displayed, instead it just gets calculated and then thrown out. Commented Aug 30, 2016 at 15:41

1 Answer 1

2
fib=[0,1]
for i in range(0,700):
    fib.append(fib[len(fib)-2]+fib[len(fib)-1])
    print(fib[len(fib)-1])
answer=input('Do you want a range of numbers or single?')
if answer=='single':
    number=int(input('Which number?[index]: '))
    print(fib[number])
elif answer=='range':
    firstNumber=int(input('From[index]: '))
    secondNumber=int(input('To[index]: '))
    print(fib[firstNumber:secondNumber])
else:
   print('Error')

Maybe this will work for you

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

1 Comment

Not sure if he's using Python 2 or 3, but it looks like he's using 3, so those prints will need parens and raw_input can be just input.

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.