與小卡特一起學python 第1章 出發吧 1-2猜數遊戲
import random
secret = random.randint(1,99) #隨機神秘數
guess = 0 #遊戲者輸入的數字
tries = 0 #重試次數
print ("AHOY! I'm the Dread Pirate Roberts, and I have a secret!歡迎光臨,這是一個猜數遊戲!")
print ("It is a number from 1 to 99. I'll give you 6 tries.這是一個1-99的一個數字,您有六次機會!")
while guess != secret and tries < 6:
guess = int(input("What's yer guess?請輸入你的數字"))#input要轉換成int 書中沒有註明,所以除錯時出錯。
print(guess,secret,tries) #這行是我加入,想知道當前三個的數值是多少。
if guess < secret:
print ("Too low,ye scurvy dog!太小了哦,請重新輸入")
elif guess > secret:
print("Too high,landlubber!太大了,請重新輸入")
#這行空格
tries = tries +1
#這行空格
if guess == secret:
print ("Avast!Ye got it! Found my secret,ye did!太棒了,恭喜猜對了。")
else:
print("No more guesses!Better luck next time,matey!次數用盡,遊戲結束。")
print("The sectet number was秘密數字是",secret)
secret = random.randint(1,99) #隨機神秘數
guess = 0 #遊戲者輸入的數字
tries = 0 #重試次數
print ("AHOY! I'm the Dread Pirate Roberts, and I have a secret!歡迎光臨,這是一個猜數遊戲!")
print ("It is a number from 1 to 99. I'll give you 6 tries.這是一個1-99的一個數字,您有六次機會!")
while guess != secret and tries < 6:
guess = int(input("What's yer guess?請輸入你的數字"))#input要轉換成int 書中沒有註明,所以除錯時出錯。
print(guess,secret,tries) #這行是我加入,想知道當前三個的數值是多少。
if guess < secret:
print ("Too low,ye scurvy dog!太小了哦,請重新輸入")
elif guess > secret:
print("Too high,landlubber!太大了,請重新輸入")
#這行空格
tries = tries +1
#這行空格
if guess == secret:
print ("Avast!Ye got it! Found my secret,ye did!太棒了,恭喜猜對了。")
else:
print("No more guesses!Better luck next time,matey!次數用盡,遊戲結束。")
print("The sectet number was秘密數字是",secret)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/220205/viewspace-2065327/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 與小卡特一起學python 第1章 出發吧 課後練習題Python
- 與小卡特一起學python 第3章 基本數學運算Python
- 與小卡特一起學python 第14章 物件Python物件
- 與小卡特一起學python 第22章 檔案輸入與輸出Python
- 與小卡特一起學python 第1章 出發吧 1-1練習我們第一個真正的程式Python
- 與小卡特一起學python 第19章 聲音Python
- 與小卡特一起學python 第20章 使用pyqtPythonQT
- 與小卡特一起學python 第16章 圖形 Pygame學習PythonGAM
- 與小卡特一起學python 第10章 遊戲時間到了 程式碼清單Python遊戲
- 與小卡特一起學python 第13章 函式-積木Python函式
- 與小卡特一起學python 第21章 列印格式化與字串Python字串
- 與小卡特一起學python 第4章 資料的型別Python型別
- 與小卡特一起學python 第11章 巢狀與可變迴圈Python巢狀
- 與小卡特一起學python 第14章 物件 動手試一試Python物件
- 與小卡特一起學python 第9章 全都為了你-註釋Python
- 與小卡特一起學Python 第15章 模組 及動手試一試Python
- 與小卡特一起學python 第17章動畫精靈和碰撞檢測Python動畫
- 與小卡特一起學python 第18章 一種新的輸入-事件Python事件
- 與小卡特一起學python 第8章 動手試一試原始碼Python原始碼
- 與小卡特一起學python 第10章 遊戲時間到了 pygame安裝及素材圖片準備Python遊戲GAM
- 與小卡特一起學python 第2章 記住記憶體和變數 2-1練習Python記憶體變數
- 與小卡特一起學python 第13章 函式-積木 動手試一試Python函式
- 與小卡特一起學python 第8章 轉圈圈 FOR迴圈和條件迴圈Python
- 與小卡特一起學python 第12章 收集起來,列表與字典 動手試一試Python
- 與小卡特一起學python 第11章 巢狀與可變迴圈 動手試一試Python巢狀
- 與小卡特一起學python 第2章 記住記憶體和變數 課後 動手試一試Python記憶體變數
- 【python小練習】簡單的猜數字遊戲Python遊戲
- 與小卡特一起學python 第5章 輸入 測試題和動手試一試Python
- 與小卡特一起學python 第7章 判斷再判斷 7-1-2-3-6-7Python
- 與小卡特一起學python 第5章 輸入 5-1,2,3,4 input()輸入函式Python函式
- 【數學】組合數學 - 卡特蘭數
- 與小卡特一起學python 第6章 gui-圖形使用者介面 測試和動手試一試PythonGUI
- 微課|中學生可以這樣學Python(例6.3):猜數遊戲Python遊戲
- 猜數字遊戲遊戲
- Java學習筆記(一) 猜數遊戲Java筆記遊戲
- 與小卡特一起學python 第6章 gui-圖形使用者介面 6-1-2-3-4-5 gui使用PythonGUI
- Shell猜數字遊戲遊戲
- 猜數字小遊戲遊戲