Skip to content Skip to sidebar Skip to footer

Python: Not All Arguments Converted During String Formatting

This code gives an error print('type a whole number:') n = input() if n % 2 == 1: print('Odd'); else: print('Even'); I'm assuming there's something special I have to do to

Solution 1:

Here is how to fix it:

n = int(input("type a whole number:"))

Since input() returns a string, you need to convert it to an int first, using int().

Solution 2:

You need to convert n to an integer first, in py 3.x input() returns a string.:

n = int(input())

Solution 3:

Convert the user input n to an integer first. i.e. Simply Change :

n = input()

To :

n = int(input())

Also, input() can take a string as an argument, which is printed before taking the input. So, you can change

print('type a whole number:')
n = int(input())

To

n = int(input('type a whole number:'))

Post a Comment for "Python: Not All Arguments Converted During String Formatting"