简体   繁体   中英

Syntax error in python; unexpected indent

The aim of this code is to grade the score which is between 0.0 and 1.0. below 0.6 is F, >= 0.6 is D, >= 0.7 is C, >= 0.8 is B and >= 0.9 is A; and I'm getting an error.

inp = raw_input ('Enter score between 0.0 & 1.0 here: ')
if inp == > 0.9:
 print A 
elif inp == > 0.8:
 print B 
elif inp == > 0.7:
 print C
elif inp == >0.6:
 print D 
else inp < 0.6:
 print F 
inp = float(raw_input('Enter score between 0.0 & 1.0 here: '))  ## This line takes the raw input in from command prompt. float('') casts the raw_input string to a float type number. 
if inp >= 0.9:
    print "A"     
elif inp >= 0.8:
    print "B" 
elif inp >= 0.7:
    print "C"
elif inp >=0.6:
    print "D" 
else:
    print "F" 

Rewrite your code as above. You don't need to have a logical statement for "else" and you don't have 2 equal signs for greater than or equals. Also, remember to convert your string input to integer.

Use "input" instead of raw_input if your on python version 3 or higher.

inp = float(input ('Enter score between 0.0 & 1.0 here: '))

Python knows where to end functions using indents/spaces. For example,

if(1 == 1):
    print "I indented here"

The code below causes an error because Python sees nothing is in the if statement

 if(1 == 1):
 print "I indented here"

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