我正在尝试在PYTHON制作小型随机猜谜游戏,但是在用户播放之后它可以正常运行我希望它恢复到开始并允许用户在输入“y”时再次播放。所以它会恢复到代码的顶部。我理解它的循环,但我无法弄清楚如何使它工作。 非常感谢任何帮助!
import random
bet = input("How much would you like to bet?")
print ("You are betting €",bet,)
win = int(bet) * int(2)
print('Pick either 1 or 0')
number = random.randint(0,1)
guess = 0
while number < 2:
guess_number = int(input('Enter a number:'))
if guess_number == number:
print('Your guess is correct the number is',number)
print("you have won €",win,)
break
if guess_number >=2:
print ("Number too high")
else:
print("you are wrong, you have lost €",bet,)
break
play_again = input("Play Again? y/n")
y = bet
n = print("bye")
if play_again == y:
bet
答案 0 :(得分:1)
将整个代码(var option = {
showLines: true,
scales: {
yAxes: [{
display: true,
ticks: {
beginAtZero:true,
min: 0,
max: 100
}
}]
}
};
除外)放在import random
循环中。
while
答案 1 :(得分:0)
您也可以将代码放在函数中:
<hr style="background-color: #dd3333" />