如果答案是错误的,我如何使函数重复,所以程序选择了一个新的数字。
制造一个时间循环
import random, sys
def randomNumber(diceRoll):
while True:
print('Pick a number 1 to 6')
userEntry = int(input())
if diceRoll == userEntry:
print('Correct')
sys.exit()
if diceRoll != userEntry:
print('Wrong, try again')
print('The number generated was ' + str(diceRoll))
continue
r = random.randint(1, 6)
outcome = randomNumber(r)我希望程序再次询问用户的随机数,如果用户猜错了,而是用一个新的数字。
发布于 2019-01-20 14:10:58
如果猜错了,就重置diceRoll吧。
import random, sys
def randomNumber(diceRoll):
while True:
print('Pick a number 1 to 6')
userEntry = int(input())
if diceRoll == userEntry:
print('Correct')
sys.exit()
if diceRoll != userEntry:
print('Wrong, try again')
print('The number generated was ' + str(diceRoll))
diceRoll = random.randint(1, 6)
continue
r = random.randint(1, 6)
outcome = randomNumber(r)https://stackoverflow.com/questions/54277237
复制相似问题