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 trial

Python Comparison Solution

trouble with fizzbuzz challenge

Not able to fix this problem. Please help !

Please enter your name: baishali
Please enter a number: 15
Traceback (most recent call last):
File "challenge.py", line 3, in <module>
is_fizz = number % 3 == 0
TypeError: not all arguments converted during string formatting

Can you post all of your code?

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

All input from the user is received as a string. So "15" will need to be converted using int() first.

>>> number = "15"
>>> is_fizz = number % 3 == 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>> 
>>> is_fizz = int(number) % 3 == 0
>>> is_fizz
True

Some coders choose to place the input() within an int() to covert the user input immediately into an integer. This could raise a warning if the user enters something that can't be converted into an integer.

You may be asking how this happens. When the operator % has a left-side argument that is a number, the operator is interpreted as the arithmetic modulo.

In addition to performing the modulo operation on numbers, the % operator is also overloaded by string objects to perform old-style string formatting (also known as interpolation). The syntax for string formatting is described in the Python Library Reference, section printf-style String Formatting.

Post back if you need more help. Good Luck!!

Ashwin Kumar
Ashwin Kumar
680 Points

if you have defined number in the input statement like: number = input("Please enter a number: ")

add this next to the above line: number = int(number) basically it reassigns the number variable with a integer version of the number variable previously stored.

you can then do any math operation on it.

Hope this helps.