Python學習者(2.7.5版)。在
python小程序、目前我正在開發一個簡單的測試腳本,允許用戶重新回答問題,并限制用戶錯誤回答問題的機會。在
因此設置了5個總限制,并顯示一條消息(例如“END!”)當達到限制時將顯示給用戶。所有問題都有這個限制。在
python用什么編譯器。當我測試下面提到的腳本時,我發現了幾個問題。在
1)即使問題1被錯誤回答了5次,問題2仍然會顯示,如果已經達到限制,我如何防止下一個問題出現?在
python基礎教程,2)我想問我應該在哪里插入結束消息的代碼(“end!”)如果達到了極限?在
非常感謝!在def quiz():
score = 0
counter = 0
print "Please answer the following questions:"
print "Question 1 - ?"
print "a."
print "b."
print "c."
while counter <5:
answer = raw_input("Make your choice:")
if answer == "c":
print("Correct!")
score = score +1
else:
print("Incorrect!")
counter = counter +1
print "Question 2 - ?"
print "a."
print "b."
print "c."
while counter <5:
answer2 = raw_input("Make your choice:")
if answer2 == "a":
print("Correct!")
score = score +1
else:
print("Incorrect!")
counter = counter +1
print ("Your score is ") + str(score)
另外,代碼似乎有點偏離了復制粘貼功能。很抱歉給您帶來不便
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态