猜年齡遊戲

2021-10-09 16:46:22 字數 966 閱讀 3679

猜年齡遊戲公升級版

要求:允許使用者最多嘗試3次

每嘗試3次後,如果還沒猜對,就問使用者是否還想繼續玩,如果回答y或y, 就繼續讓其猜3次,以此往復,如果回答n或n,就退出程式

如何猜對了,就直接退出

import random

#生成隨機數

n = random.randint(0,

200)

#允許使用者最多嘗試3次

count =

0while count <3:

# 輸入年齡

age =

int(

input

("猜年齡:"))

count +=

1if age > n:

print

("猜大了"

)elif age < n:

print

("猜小了"

)elif age == n:

print

("猜對了"

)break

# 猜對了,直接退出

else

:print

("非法輸入"

)if count ==3:

choose =

input

("否還想繼續玩,回答y或y, 繼續玩/回答n或n,退出程式:"

)if choose ==

'y'or choose ==

'y':

count =

0continue

elif choose ==

'n'or choose ==

'n':

print

("退出程式"

)break

else

:print

("非法輸入"

)continue

print

(f"\n正確的年齡是歲"

)

猜年齡小遊戲

1.給定年齡,使用者可以猜三次年齡 2.年齡猜對,讓使用者選擇兩次獎勵 3.使用者選擇兩次獎勵後可以退出 age count 0 計數 age 18 while age count 3 age inp input 請輸入你猜的年齡 與使用者互動 if not age inp.isdigit prin...

Python Python 猜年齡的遊戲

遊戲規則 允許使用者最多嘗試3次 每嘗試3次後,如果還沒猜對,就問使用者是否還想繼續玩,如果回答y或y,就繼續讓其猜3次,以此往復,如果回答n或n,就退出程式 如何猜對了,就直接退出 1 age 18 2 count true 3while count 45 for i in range 3 6 g...

猜年齡遊戲函式版

1.在猜年齡的基礎上編寫登入 註冊方法,並且把猜年齡遊戲分函式處理,如 2.登入函式 3.註冊函式 4.猜年齡函式 5.選擇獎品函式 import json real age 18prize list 好迪洗髮水 綠箭俠 小豬佩奇 布娃娃 再來一次 import random user prize ...