I'm trying to make a program in Python that takes in an input for how many times to repeat the Fibonacci sequence.
...
i=1
timeNum= input("How many times do you want to repeat the sequence?")
while i <= timeNum:
...
i += 1
How can I force that input to be an integer? I can't have people repeating the sequence 'apple' times? I know it involves int()
but I don't know how to use it. Any and all help is appreciated.
You could try to cast to an int, and repeat the question if it fails.
Though using try-catch for handling is taboo in some languages, Python tends to embrace the "ask for forgiveness, not permission approach". To quote the section on EAFP in the Python glossary: