我想在python中進行「猜數字」遊戲,其中我選擇最小和最大數字,如果我選擇的數字更低或更高,我希望它重複該問題,我怎樣才能做到這一點?如果輸出爲假,則重複輸入
這裏是我的代碼:
import random
import time
print("Welcome to the guessing game!")
time.sleep(1)
print("Choose your minumum number")
minnum=input("Min: ")
print(" ")
print("Choose your maximum number")
maxnum=input("Max: ")
print(" ")
print("Enter your number")
num = input("Number: ")
print(" ")
q = random.randint(int(minnum), int(maxnum))
def game():
if int(num) < q:
print("The number is higher")
if int(num) > q:
print("The number is lower")
if int(num) == q:
print("Congratulations! you won!")
break
game()
print(" ")
print(" ")
input("Press enter to exit")
你不能有外部的'break'聲明的循環。 – Tagc