CP2020-40923218

  • Home
    • Site Map
    • reveal
    • blog
  • 首頁
  • 關於更新
    • 十月份更新
    • 十一月更新
    • 十二月更新
    • 一月份更新
  • 心得
  • 課程內容(HW1)
    • Customer Relations
    • Overview
    • Operational Procedures
      • Customer Service Key Principles
    • Effective Listening
      • Listening skills
    • Taking Ownership
      • Apologizing When Appropriate
      • Show Empathy
    • Remain Courteous and Professional
      • Timeliness
      • Keeping the Customer Informed
    • Problem Resolution and Follow-Up
    • Proper Treatment of a Customer’s Property
    • Putting it All Together
  • 課程內容(HW2)
    • 作業之一(分組數列)
    • 作業之二(是否有加退選)
    • 作業之三()
  • 課程內容(HW3)
    • 19題
    • 25題
      • 猜數字測試
    • 26題
  • 網頁來自Github
    • 運作原理
25題 << Previous Next >> 26題

猜數字測試

import random

print("test,輸入答案")
b = int(input())#答案

print("輸入最大值")
最大值 = input("最大值=")

print("輸入最小值")
最小值 = input("最小值=")
a = random.randint(int(最小值),int(最大值))#數字
start = True

while start:
    print(a)
    if a < b:
        print("再高")
        最小值 = a
        a = random.randint(int(最小值),int(最大值))
    elif a > b:
        print("再低")
        最大值 = a
        a = random.randint(int(最小值),int(最大值))
    elif a == b:
        print(a)
        start = False
print("完成")

解釋:

輸入答案、最小值和最大值後,丟入迴圈進行判斷,當猜測的數字小於答案時,就將該猜測數字更改為最小值,反之,當猜測的數字大於答案時,就將該猜測數字更改為最大值,直到猜中答案,結束程式。

結果:


25題 << Previous Next >> 26題

Copyright © All rights reserved | This template is made with by Colorlib