# python question

i = input("What's the value of 2+3?\n")

if i == 5:
print("Correct!")

else:
print("Failed...")

why this code doesn't work correctly?

answered Aug 8 by (260 points)
edited Aug 12 by Akshay Maloo

i = int(input("What's the value of 2+3?\n"))

if i == 5:
print("Correct!")

else:
print("Failed...")

OR

we can convrt directly the the no 5 into "5" string

commented Aug 19 by (140 points)
when i=5 correct
commented Aug 20 by (480 points)
Why is this question getting flagged? I see nothing wrong.
answered Aug 9 by (180 points)
This code isn't working properly because the input() function takes string as input.. Not int or floating point values..
In the if statement you wrote: you set the condition to something like this: if input == 5. Here, 5 which is an int doesn't match the actual input "5" a string.. That's why. Here is the fixed script if you need.

userInput = input("Enter your number: ")

if userInput == "5": # Here 5 is a string
print("I ate all my toes.")
else:
print("I didn't eat all my toes.")

Hope I have helped...
answered Aug 10 by (5,280 points)
When reading user input in Python, it is always taken as string even if a user enters a number.

As a result in this case, you could either carry on reading in string and convert the input to integer or read the input directly as an integer by:

i = int(input("What's the value of 2+3?\n"))
answered Aug 11 by (140 points)
Because they have not mentioned answering variable I printed after double inverted commas and should be separated by comma
answered Aug 15 by (140 points)
it is so beacause u are taking input as string

so change the first line of your code

i=int(input("What is the value of 2+3\n"))
answered Aug 16 by (240 points)

THIS CODE SHOULD WORK PROPERLY:-

s1 = "What's the value of 2+3?

a1 = "5"

i1 = int(input(s1))

if i1 == a1 :

print("Gotcha!")

else :

print("Uh uh! Wrong one!")

answered Aug 17 by (150 points)

i =int( input("What's the value of 2+3?\n"))

if i == 5:
print("Correct!")

else:
print("Failed...")

answered Aug 19 by (140 points)
i is getting string as the input.int &string cannot manipulate in sometime in the program.so that it is Failed
answered Aug 20 by (480 points)
edited Aug 26 by Rahul Choubey

input() takes its input as a string, so there are two options:

The downside is that you could get an error if the user enters an explicit string such as "pie"

To get around this, here's the full solution:

try:

i = int(input("What's the value of 2+3?\n"))

except:

print("Failed...")

else:
if i == 5:
print("Correct!")
else:
print("Failed...")

2. change 5 to a string

downside: it looks strange

here's the full code(it sort of gets around this issue)

i = input("What's the value of 2+3?\n")
if i == str(5):
print("Correct!")
else:
print("Failed...")