简体   繁体   中英

TypeError: 'float' object is not callable: how to fix?

Here's my code:

number1 = int(input("Insert a Number: "))
if (number1 % 2) == 0:
   print(number1 + "is even.".format(number1))
else:
   print(number1 + "is odd.".format(number1))

What's wrong with this?

Try one of these for printing:

print('{} is even'.format(number1))

or

print(str(number1) + ' is even')

I strongly recommend using the first one.

or for python 3.6+ :

print(f"{number1} is even")

Use

print(“{} is even.”.format(number1))

Or if you use python3:

print(f”{number1} is even.”)

You should write the code like this

number1 = int(input("Insert a Number: "))
if (number1 % 2) == 0:
   print(str(number1) + " is even.")
else:
   print(str(number1)+ " is odd.")

Alternative you could write:

number1 = int(input("Insert a Number: "))
if (number1 % 2) == 0:
   print("{} is even.".format(number1))
else:
   print("{} is odd.".format(number1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM