请帮助解决问题。
鉴于:
腿骨列表。有必要迭代列表并找到输入的单词与列表中的单词的匹配。两次尝试,每次尝试后立即响应。此外,您需要计算列表中有多少项目。
这是我生的(我无法以任何方式计算总数):
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform",
"intermediate cuneiform", "medial cuneiform"]
total = 0
guess = ""
def bones_func (guess, foot_bones, total):
guess = input ("Enter the name of the foot bone: ")
for bone in foot_bones:
if guess.lower()== bone:
print ("Correct")
total += foot_bones.count(bone)
else:
print ("Incorrect")
total += foot_bones.count(bone)
bones_func (guess, foot_bones, total)
bones_func (guess, foot_bones, total)
print (total)
这是我在互联网上找到的,完全让我陷入了昏迷:
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform", "intermediate cuneiform", "medial cuneiform"]
def foot_bones_quiz(guess, answer):
total_bones = 0
for bones in answer:
total_bones += bones.count(bones)
if guess.lower() == bones.lower():
return True
else:
pass
return False
print("Total number of identified bones: " + str(total_bones))
user_guess = input("Enter a bone: ")
print("Is " + user_guess.lower() + " a foot bone?" , foot_bones_quiz(user_guess, foot_bones))
user_guess = input("Enter another bone: ")
print("Is " + user_guess.lower() + " a foot bone?", foot_bones_quiz(user_guess, foot_bones))
我不清楚猜测变量在解决方案中的来源?它们与 user_guess 有什么关系?答案变量与foot_bones 有何关系?如何在列表中进行完整计数?谢谢
def foot_bones_quiz(guess, answer):
函数变量的描述是函数guess
的参数。这里函数被调用,它
foot_bones_quiz(user_guess, foot_bones)
进入参数,进入变量guess
user_guess
answer
foot_bones
该列表有一个方法
count
。您需要将骨骼的名称放入计数中并获得结果。例子:
PS。我不是医生,所以我不知道它们是
"lateral cuneiform", "intermediate cuneiform", "medial cuneiform"
单独的骨头还是搜索也应该通过部分巧合找到,例如:附言 如果您的任务是手动编写搜索功能,那么您需要知道
функции
:условия
和циклы
。