【发布时间】:2021-05-02 10:47:11
【问题描述】:
你好,我需要帮助我一直在做的这个程序,这是一个会问用户琐事问题然后计算用户智商的程序,我设法让程序问用户问题,然后添加一个 1当用户正确回答问题时,名为“IQ”的列表,然后我让计算机计算列表中有多少个,以检查用户得到的分数。
然后我第二天尝试让它,如果你没有输入指定答案之一,程序会让你再次输入答案,并输出一条消息,要求再次输入你的答案。
我对编程还很陌生,所以任何帮助或批评都将不胜感激。
import time
print("Welcome! This is the special IQ quiz...")
time.sleep(2)
print("You start at 60 IQ and you get 20 IQ for each question you get correct...")
time.sleep(2)
print("Let's see how smart you are, good luck!\n")
time.sleep(1)
iq = []
qustn_answrd = []
while len(qustn_answrd) <= 7:
qustn1 = input("What's the name of the river that runs through Egypt?\n>> The Mississippi River\n>> The Nile\n>> The Yangtze River\n>> The Amazon River\n")
if qustn1 == "The Nile":
iq.append(1)
qustn_answrd.append(1)
elif qustn1 == "The Mississippi River" or "The Yangtze River" or "The Amazon River":
qustn_answrd.append(1)
elif qustn1 != "The Nile" or "The Mississippi River" or "The Yangtze River" or "The Amazon River":
print("That is not a valid answer, make sure to input one of\nthe answers and if you did, make sure its written how it is displayed in the question...")
else:
break
while len(qustn_answrd) <= 7:
qustn2 = input("Who was the Prime Minister before Theresa May?\n>> John Major\n>> Tony Blair\n>> David Cameron\n>> Harold Wilson\n")
if qustn2 == "David Cameron":
iq.append(1)
qustn_answrd.append(1)
elif qustn2 == "John Mayor" or "Tony Blair" or "Harold Wilson":
qustn_answrd.append(1)
else:
print("That is not a valid answer, make sure to input one of\nthe answers and if you did, make sure its written how it is displayed in the question...")
break
while len(qustn_answrd) <= 7:
qustn3 = input("Who did Orlando Bloom play in the Pirates In The Caribbean?\n>> Captain Jack Sparrow\n>> Hector Barbossa\n>> Davy Jones\n>> Will Turner\n")
if qustn3 == "Will Turner":
iq.append(1)
qustn_answrd.append(1)
elif qustn3 == "Captain Jack Sparrow" or "Hector Barbossa" or "Davy Jones":
qustn_answrd.append(1)
else:
print("That is not a valid answer, make sure to input one of\nthe answers and if you did, make sure its written how it is displayed in the question...")
break
while len(qustn_answrd) <= 7:
qustn4 = input("What's the highest mountain in the world?\n>> Mount Everest\n>> K2\n>> Kangchenjunga\n>> Lhotse\n")
if qustn4 == "Mount Everest":
iq.append(1)
qustn_answrd.append(1)
elif qustn4 == "K2" or "Kangchenjunga" or "Lhotse":
qustn_answrd.append(1)
else:
print("That is not a valid answer, make sure to input one of\nthe answers and if you did, make sure its written how it is displayed in the question...")
break
while len(qustn_answrd) <= 7:
qustn5 = input("How many wives did Henry VIII have?\n>> Eight\n>> Six\n>> Seven\n>> Nine\n")
if qustn5 == "Six":
iq.append(1)
qustn_answrd.append(1)
elif qustn5 == "Eight" or "Seven" or "Nine":
qustn_answrd.append(1)
else:
print("That is not a valid answer, make sure to input one of\nthe answers and if you did, make sure its written how it is displayed in the question...")
break
while len(qustn_answrd) <= 7:
qustn6 = input("What is the capital of Spain\n>> Madrid\n>> Barcelona\n>> Seville\n>> Granada\n")
if qustn6 == "Madrid":
iq.append(1)
qustn_answrd.append(1)
elif qustn6 == "Barcelona" or "Seville" or "Granada":
qustn_answrd.append(1)
else:
print("That is not a valid answer, make sure to input one of\nthe answers and if you did, make sure its written how it is displayed in the question...")
break
while len(qustn_answrd) <= 7:
qustn7 = input("Who is the highest selling fiction author of all time?\n>> Barbara Cartland\n>> William Shakespeare\n>> Agatha Christie\n>> Danielle Steel\n")
if qustn7 == "Agatha Christie":
iq.append(1)
qustn_answrd.append(1)
elif qustn7 == "Barbara Cartland" or "William Shakespeare" or "Danielle Steel":
qustn_answrd.append(1)
else:
print("That is not a valid answer, make sure to input one of\nthe answers and if you did, make sure its written how it is displayed in the question...")
break
if len(iq) == 0:
print("You answered none of the questions correctly so you have an IQ of 60")
if len(iq) == 1:
print("You answered 1 out of 7 questions correctly so you have an IQ of 80")
if len(iq) == 2:
print("You answered 2 out of 7 questions correctly so you have an IQ of 100")
if len(iq) == 3:
print("You answered 3 out of 7 questions correctly so you have an IQ of 120")
if len(iq) == 4:
print("You answered 4 out of 7 questions correctly so you have an IQ of 140")
if len(iq) == 5:
print("You answered 5 out of 7 questions correctly so you have an IQ of 160")
if len(iq) == 6:
print("You answered 6 out of 7 questions correctly so you have an IQ of 180")
if len(iq) == 7:
print("You answered all of the questions correctly so you have an IQ of 200")
【问题讨论】:
-
您是否遇到过具体问题?我没听懂你的问题是什么。
标签: python input while-loop break