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
    • 運作原理
19題 << Previous Next >> 猜數字測試

25題

(完成度100%)

import random,time

start = True
start2 = True

print("派森醬:嗨嗨~想跟我玩小遊戲嗎~~(回答yes or no)")
while start: 
    回答 = input()
    if "no" in 回答:
        print("派森醬:不要這樣嘛~~陪我玩嘛~~(回答yes or no)")
    elif "yes" in 回答:
        print("派森醬:耶~~~那要來囉")
        time.sleep(1.5)
        start = False
    else:
        print("(請輸入yes or no)")
        
print("派森醬:我們來玩猜數字,我們先來訂個範圍八")
time.sleep(1.5)
print("派森醬:先給我一個最小值")
最小值 = input()
time.sleep(1.5)

print("派森醬:再給我一個最大值")
最大值 = input()
time.sleep(1.5)

print("派森醬:我把眼睛閉起來了,打上你想要給我猜的數字八")
b = int(input())#答案
time.sleep(1.5)

a = random.randint(int(最小值),int(最大值))#數字

print("派森醬:那我開始猜囉!!")
time.sleep(1.5)

while start2:
    print("派森醬:讓我想想看...")
    time.sleep(1.5)
    print("派森醬:是這個數字嗎?(請回答yes or no)",a)
    回答2 = input()
    time.sleep(1.5)
    if "no" in 回答2:
        print("派森醬:不是嗎?!那是再高還是再低?(請回答 hight 或 lower )")
        回答3 = input()
        #time.sleep(1.5)
        if "hight" in 回答3 and a < b:
            最小值 = a
            a = random.randint(int(最小值),int(最大值))
        elif "lower" in 回答3 and a > b:
            最大值 = a
            a = random.randint(int(最小值),int(最大值))
        else:
            print("(請輸入 hight or lower)")
    elif "yes" in 回答2:
        start2 = False
    else:
        print("(請輸入yes or no)")
        
print("派森醬:耶~~猜到了~~")
time.sleep(1.5)
print("派森醬:謝謝你陪我玩,下次見~~")

心得:

這次我跟上一題一樣,先複製解答來推倒程式中的邏輯,最後完成出第一號程式碼,但是,元程式碼是用(其實我自己也不太確定)猜測數做加減來給出答案,於是我就在想能不能改用縮小猜測範圍來給出答案,於是產生出上面的程式碼,與原程式碼多了七行,但是改變了猜測方式,而且多了自訂義範圍,程式成功跑出來的時候,真的是很開心,開始覺得Python很有趣了。

備註:

用kaggle可以跑中文回覆,用小白窗只能跑英文回覆

結果:


19題 << Previous Next >> 猜數字測試

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