【发布时间】:2012-11-07 23:18:03
【问题描述】:
我有一个问题,需要我接受用户输入并返回该值或高于该值的所有项目,最高可达 100
我问用户他想从我拥有的一组数据中看到什么成绩。
所以我会让用户输入一个等级,然后我会返回该等级或更高等级的人的所有记录。
这是我目前所拥有的
我从中提取的一小部分数据看起来像这样
['Bud', 'Abbott', 51, 92.3]
['Don', 'Adams', 51, 90.4]
['Mary', 'Boyd', 52, 91.4]
['Jill', 'Carney', 53, 76.3]
['Hillary', 'Clinton', 50, 82.1]
['Randy', 'Newman', 50, 41.2]
到目前为止,我的代码只是一些确保用户输入正确函数的 if 和 elif 语句。 此功能将起作用,如果用户输入字母 g,程序将要求一个等级阈值,然后将返回具有该等级及以上等级的任何数据行。
例如,如果我是用户,我输入 g 然后输入 90 我只会找回这三行
['Bud', 'Abbott', 51, 92.3]
['Don', 'Adams', 51, 90.4]
['Mary', 'Boyd', 52, 91.4]
此外,如果用户输入字母 S,它会找到该部分的记录并返回该部分中的所有学生 所以如果用户输入 s 然后 50 程序将返回
['Hillary', 'Clinton', 50, 82.1]
['Randy', 'Newman', 50, 41.2]
目前我写的代码是这样的
def Query ():
input("enter query type (g or s):")
#checks user's input and takes user to grades
if (operator == "g"):
print("You have chosen to query Grades")
GradeThreshold=input("enter the Grade threshold:")
#checks user's input and takes user to section
elif (operator == "s"):
print("You have chosen to query Section")
SectionNumber=input("enter the section:")
elif (operator != "g") and (operator != "s"):
print("Invalid entry. Please re-enter the operation from above.")
return()
我对如何接受用户输入并让它从我上面的数据列表中选择等级范围或部分编号感到困惑。请帮帮我。
【问题讨论】:
-
您可以从正确缩进代码示例开始。如您所知,缩进是 Python 语法的一部分。
标签: list python-3.x call range threshold