如何python做一個(gè)1-100的猜數(shù)游戲,,告訴我我猜的次數(shù)
完整的程序參考:
import randomsecret = random.randint(1,100)guess = 0tries = 0while int(guess) != secret and tries < 10: #最多猜10次print("第%d次,"%(tries+1),end='');guess = input ("輸入你的數(shù):")ifint(guess) < secret :print ("太小!")elifsecret < int(guess):print ("太大")tries = tries + 1if int(guess) == secret :print ("你猜對(duì)了,,共%d次"%(tries))else:print ("你10次都沒(méi)猜對(duì),數(shù)字為:",secret)
相關(guān)推薦
便查問(wèn)答是一款實(shí)用的網(wǎng)絡(luò)熱門(mén)知識(shí)問(wèn)答平臺(tái),專(zhuān)注于分享你不知道的知識(shí),、經(jīng)驗(yàn)及生活問(wèn)題,在這里所有人都能找到答案歡迎網(wǎng)友參與討論,。