Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialStudent5 Saxon
2,525 PointsTypeError: 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?
1 Answer
Stuart Wright
41,120 PointsThe 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.