我在解决python中的循环时遇到问题。此外,我在理解如何为我的Python测验分配添加循环时遇到问题。有人可以就我的这个问题给我指导。下面是我在python多项选择测验中的当前代码。
from datetime import datetime
now = datetime.now()
# showing the current date you're taking the quiz
print("Today's Date is:")
print('%s/%s/%s' % (now.month, now.day, now.year))
print("")
#this will print out my welcome statement and ask you for your name
print('Hello welcome to my Quiz, what is your name?')
#definied the variable username so that the user could type in their name
usersname = input()
print ("")
print('It is nice to meet you, ' + usersname)
print("")
level = input ('Please select a difficulty (easy, medium, or hard): ')
print("")#I just used this to add some space between my lines
print("")#I just used this to add some space between my lines
#these are my questions
easy_questions= ["What is 20 + 2 __1__", "What is the capital of Georgia__2__","If john has $4 and buys a candy bar for $3.50, how much money does he have left over__3__","What is the name of the NBA basketball team in Georgia__4__","What is the name of the NFL team in Georgia__5__","How many toys do I have if I sell 3, but had 8 toys originally__6__","How many Bad Boy movies are there__7__","How many Fast Furious movies are there__8__","What is 10 * 5 __9__","What city does the UGA team play in__10__"]
medium_questions= ["What is 20 + 2 __1__", "What is the capital of Georgia__2__","If john has $4 and buys a candy bar for $3.50, how much money does he have left over__3__","What is the name of the NBA basketball team in Georgia__4__","What is the name of the NFL team in Georgia__5__","How many toys do I have if I sell 3, but had 8 toys originally__6__","How many Bad Boy movies are there__7__","How many Fast Furious movies are there__8__","What is 10 * 5 __9__","What city does the UGA team play in__10__"]
hard_questions= ["What is 20 + 2 __1__", "What is the capital of Georgia__2__","If john has $4 and buys a candy bar for $3.50, how much money does he have left over__3__","What is the name of the NBA basketball team in Georgia__4__","What is the name of the NFL team in Georgia__5__","How many toys do I have if I sell 3, but had 8 toys originally__6__","How many Bad Boy movies are there__7__","How many Fast Furious movies are there__8__","What is 10 * 5 __9__","What city does the UGA team play in__10__"]
答案 0 :(得分:1)
循环是非常基础的(用任何语言),所以我强烈建议你阅读它们。这是一个有用的链接:https://www.tutorialspoint.com/python3/python_loops.htm
你可以这样做:
for question in easy_questions:
answer = input(question)
check_if_answer_is_correct(answer)