Search code examples
pythonif-statementraw-input

If statement not working when using raw_input


The code works when I don't use raw_input. Not sure what I am doing wrong. I am using python 2.7.5 Here is my code:

mark = raw_input('Enter Your Marks: ')

x = mark

if x > 80:
    grade = 'HD'
elif x > 70:
    grade = 'D'
elif x > 60:
    grade = 'CR'
elif x > 50:
    grade = 'P'
else:
    grade = 'F'

print(grade)

Solution

  • raw_input() returns a string, but you are comparing against integers.

    Convert your input:

    x = int(mark)