How do i get rid of the term none here and what is it?

0

Issue

I’ve created a basic addition statement, i am aware that input is being read as a string but my code prints out "none" before taking an input (see below). How do i take integer as an input??

# code example
print("This is a calculator")
a = input(print("Enter the first number"))
b = input(print("Enter the second number"))
print("sum =", a + b)

This outputs:

This is a calculator
Enter the first number
None5
Enter the second number
None6
sum = 56

Solution

remove print() in the first two lines:

a = input("Enter the first number")
b = input("Enter the second number")

instead of:

a = input(print("Enter the first number"))
b = input(print("Enter the second number"))

None is the return of the print() function so since input() prints what you input to it you are printing the returned None value. Then the print statement will still print the prompt. However you want to let input() print the prompt as described above.

Answered By – Eli Harold

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More