1 import random 2 3 secret = random.randint(1, 30) 4 guess = 0 5 tries = 0 6 7 print("我叫丁丁,我有一個祕密數字!") 8 print("數字從1到30,你只有6次機會!") 9 10 while int(guess) != secret and tries < 6: 11 print("你猜的數字是?") 12 guess = input() 13 if int(guess) < secret: 14 print("數字過小了!再猜!") 15 elif int(guess) > secret: 16 print("數字太大了!再猜!") 17 tries = tries + 1 18 if int(guess) == secret: 19 print("你真厲害!恭喜你猜對啦!") 20 else: 21 print("你猜錯6次啦,下次再玩吧!") 22 print("個人祕密數字是:", secret)