【发布时间】:2016-09-21 00:09:28
【问题描述】:
我是编程新手(3 天前刚开始),我需要有关此代码的帮助,我真的需要。
我不知道如何执行while 循环。 (在#### 行下方)。你能帮帮我吗?
我正在使用python 3.4.2 版
import random
right = 0
wrong = 0
for i in range(10):
x = random.randint (2,29)
y = random.randint (3,29)
z = (x*y)
qq = input("What's " + str(x) + " times " + str(y) + "? ")
if str(z) == str(qq):
right = right +1
print ("Correct!\n")
else:
wrong = wrong + 1
print ("Wrong the correct answer is ",str(z),"\n")
print ("You got", right, "out of 10 questions")
if right==10:
print ("Well Done! Perfect score!")
elif right>=5:
print ("Well done! try getting perfect score next time")
else:
print ("Noob")
#################################################
restart = y
while True:
yess = input ("Would you like to try again? y/n?")
if restart == yess:
print (i)
else:
break
【问题讨论】:
-
您只需将整个代码放入 while 循环中,这样它就会真正重复
标签: python python-3.x while-loop