需要有关此作业的帮助:
**使用四个全局变量
foundCount = 0
searchCount = 0
names = [ "Mary", "Liz", "Miles", "Bob", "Fred"]
numbers = [ 4, 17, 19]
def find(item):
....
def result():
....
为这两个函数的主体编写代码:
find()
接受一个参数,它在全局名称列表中查找,如果在那里找不到,则在数字列表中查找。
始终递增 searchCount,无论是否找到该项目
如果找到该项目,它会增加 foundCount 并酌情打印“Found in Names”或“Found in Numbers”。
如果找不到项目,则显示“未找到”
results() 这没有参数。它打印搜索计数的摘要:例如“总搜索:6,找到的项目:4,未找到:2”**
样品运行
**======= Loading Program =======
>>> find("mary")
Not found
>>> find("Mary")
Found in names
>>> find(0)
Not found
>>> find(19)
Found in numbers
>>> results()
***** Search Results *****
Total searches: 4
Total matches : 2
Total not found: 2**
到目前为止我所做的是:
**
foundCount = 0
searchCount = 0
names = [ "Mary", "Liz", "Miles", "Bob", "Fred"]
numbers = [ 4, 17, 19]
def find(item):
global foundcount
if item == "Mary":
printNow("Found in names")
elif item == "Liz":
printNow("Found in names")
elif item == "Miles":
printNow("Found in names")
elif item == "Bob":
printNow("Found in names")
elif item == "Fred":
printNow("Found in names")
elif item == "4":
printNow("Found in numbers")
elif item == "17":
printNow("Found in numbers")
elif item == "19":
printNow("Found in numbers")
else: printNow("Not Found")
def result():
**
我需要 def result() 函数的帮助,以便我可以在三天内完成这项作业并为我的数学考试学习.. 需要帮助来完成这项作业,因为它明天到期:(....