2024年4月15日 星期一

康軒版資訊科技-二年級搜尋演算法例子-終極密碼

教師介紹內容:
依照課本要求,寫下程式碼如下:
檔案名稱:終極密碼.py
檔案內容:
import random
ans = random.randint(1,99)
Total = 1
print("這是一個終極密碼遊戲")
guess = int(input('請輸入一個數字:'))
while guess != ans:
    if guess > ans:
        Total=Total+1
        print("太大")
        guess = int(input('請輸入一個數字:'))
    elif guess < ans:
        Total=Total+1
        print("太小")
        guess = int(input('請輸入一個數字:'))
print("完全正確,正確答案為",ans)
print("共進行",Total,"次猜測")
       

沒有留言:

張貼留言

ZeroJudge python解答:a271. 彩色蘿蔔

  a271. 彩色蘿蔔 我的解法: 這題的重點只有兩個: 每天早上先扣中毒效果,再吃蘿蔔 中毒可累加,而且吃到黑蘿蔔當天不扣毒,從隔天開始扣 t = int ( input ()) for i in range ( t ):     x , y , z ,...