import random
x=(random.randint(0,100))
while True:
try:
y=int(input("請輸入數字!"))
except ValueError:
print("報歉 我無法了解")
continue
if x<y:
print("猜大了!")
continue
elif x>y:
print("猜小了!")
elif x == y:
break
print("恭喜您 答對了!")
這是一個猜數字遊戲 裡面int定義了隻能輸入整數 如果報錯Value的話 就會傳回重新輸入數字 如果填大或者填小 都不能打破循環 隻有輸入正确的數字才會打破循環。
一個沒什麼意思的小遊戲