1. 程式人生 > >python 猜字謎遊戲(隨機數)

python 猜字謎遊戲(隨機數)

pri ext pytho port 隨機 digi orm margin randint

python 猜字謎遊戲(隨機數)
import random
times = 3
secret = random.randint(1,10)
guess = 0
print('-----------我愛吃魚----------')
temp = input("不妨猜一下我的心裏的數字:")
guess = int(temp)
while (guess != secret)and (times > 0):
temp = input("猜錯啦,請重新輸入:")
guess = int(temp)
while not temp.isdigit():

temp = input("抱歉,請輸入完整的整數:")
uess = int(temp)
times = times - 1 #每輸入錯誤一次機會就會減一
if guess == secret:
print("我暈, 你是如何知道的?!")
print("猜中了也沒有什麽獎勵!")
else:
if guess > secret:
print("大了呀!")
else:

print("小了,小了呀")
if times > 0:
print("再來試一下:",end=" ")
else:
print("機會用光了 ~~")
print("遊戲結束,不玩啦~~")


python 猜字謎遊戲(隨機數)