猜数字游戏python程序_python经典小程序:猜数字游戏
#猜數(shù)字游戲
import random #impor語(yǔ)句導(dǎo)入random模塊
guessor=0;print("#"*30) #輸出30個(gè)”#“(”##############################“)用于裝飾輸出代碼,同下
print("hello! \nwhat is you name?") #“\n”換行
print("#"*30)
Myname=input("please enter your name:")print("*"*30)print("hello {} \nlet's play game!".format(Myname))print("*"*30)
number=random.randint(1,20) #調(diào)用random函數(shù)中的randit函數(shù)(用于生成指定范圍的隨機(jī)數(shù))
print("well~"+Myname+",please guess the number between 1 and 2.\n")print("You have six guesses.\n")while guessor<=6: #while循環(huán)(循環(huán)到滿(mǎn)足條件為止)
print("tack a guess")
guess=input("please enter your number:")print("^"*30)
guess=int(guess)
guessor=guessor+1
if guess==number:print("good! your are right")break
if guessnumber:print("\ntoo big")print("%"*30)print("\nYou've run out of guesses!")
總結(jié)
以上是生活随笔為你收集整理的猜数字游戏python程序_python经典小程序:猜数字游戏的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux远程管理协议相关知识介绍
- 下一篇: zabbix解决中文乱码