编辑:以另一种方式解决了 Grades=[71,70,72] results=['y','n','x'] for index, grade in enumerate(grades): grades.index(grade) if grade in grades:成绩=输入('成绩:')打印(成绩[索引],结果[索引]) ...................... ..................................................... ……
我的代码应该给
>>>71
[71, 'y']
>>>70
[70, 'n']
>>>72
[72, 'error']
但它需要随机(?)值形成我的 if 语句。它给
>>>
grade: 71
[72, 'n']
grade:
另外,我在 input() 行得到一个 EOFerror,如果我把 raw_input()
代码是:
grades = [70,71,72]
result1 = 'y'
result2 = 'n'
result3 = 'error'
r = 'x'
grade = input('grade: ')
def get_result(r):
"""
(str) -> (str)
you're in or out
>>>71
[71, 'y']
>>>70
[70, 'n']
>>>72
[72, 'error']
"""
r = 'x'
for grade in grades:
list=[grade, r]
if grade is 71:
r = result1
elif grade is 70:
r = result2
else:
r = result3
return(list)
print(get_result(r))