Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I want to know if the user enters y it should print:

This will do the computation

But, I am getting a syntax error on IF answer=="y"

answer = str(input("Is the information correct? Enter Y for yes or N for no"))

proceed="y" or "Y" 

If answer==proceed:

print("this will do the calculation"):

else:

exit()

1 Answer

0 votes
by (108k points)

You can refer to the below approach:

if answer in ['y', 'Y', 'yes', 'Yes', 'YES']:

    print("this will do the calculation")

Another approach:

if answer.lower() in ['y', 'yes']:

    print("this will do the calculation")

For more information regarding the same, kindly refer to the python certification course. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 26, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

Browse Categories

...