这段代码的目的是对0.0到1.0之间的分数进行评分。小于0.6为F,>= 0.6为D,>= 0.7为C,>= 0.8为B,>= 0.9为A;我得到一个错误。
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"
按照上面的方法重写代码。"else"不需要逻辑语句,"大于"或"等于"不需要两个等号。另外,请记住将字符串输入转换为整数。
如果你使用的是python版本3或更高版本,请使用"input"而不是raw_input。
inp = float(input ('Enter score between 0.0 & 1.0 here: '))
Python知道在哪里结束使用缩进/空格的函数。例如,
if(1 == 1):
print "I indented here"
下面的代码会导致错误,因为Python在if语句
中看不到任何内容 if(1 == 1):
print "I indented here"