Welcome to the Treehouse Community
Looking to learn something new?
TypeError: not all arguments converted during string formatting
What does this type error mean? I'm writing a program for the collatz conjecture:
x = input("pick a number") while x != 1: if x % 2 == 0: a = x/2 print(a) else: b = 3*x + 1 print(b)
it says the TypeError is in line three(if x%2 == 0:) Does that mean that "number" is not being passed into number/2 or 3*number +1? If so, what can I use to get an int as input?
Stuart Wright41,103 Points
The input function always returns a string, even if the user inputs a number. You can't divide a string.
You might want to change your first line to:
x = int(input("pick a number"))
You will still get an error if the user enters anything that isn't an integer at the prompt, but as long as you only enter integers it will do what you want it to.