基礎之實戰猜年齡遊戲

2022-04-28 02:24:53 字數 979 閱讀 9792

'''

1.給定年齡,使用者可以猜三次年齡

2.年齡猜對,讓使用者選擇兩次獎勵

3.使用者選擇兩次獎勵後可以退出

'''

age=18

count=0

prize=

while count<3:

choice_age=input('請輸入你要猜的年齡,退出請輸入q:').strip()

if choice_age=='q':

break

if not choice_age.isdigit():

print('必須輸入數字:')

continue

choice_age=int(choice_age)

if choice_age==age:

print('恭喜你猜對了:')

print(prize)

for i in range(2):

choice = input('請輸入你要選擇的獎品或q退出:').strip()

if choice == 'q':

break

if not choice.isdigit():

print('請必須輸入數字:')

if choice in prize:

print(f'得到的獎品是:')

else:

print('請重新輸入')

continue

break

elif choice_age>age:

print('猜大了')

else:

print('猜小了')

count+=1

if count==3:

choice2=input('請選擇繼續y/y或任意鍵退出:').strip()

if choice2=='y' or choice2=='y':

count=0

else:

break

python基礎實戰之猜年齡遊戲

目錄age 18 inp age input 請輸入年齡 strip if inp age.isdigit inp age int inp age if age inp age print 猜小了 elif age inp age print 猜大了 else print 猜對了 else prin...

猜年齡遊戲

猜年齡遊戲公升級版 要求 允許使用者最多嘗試3次 每嘗試3次後,如果還沒猜對,就問使用者是否還想繼續玩,如果回答y或y,就繼續讓其猜3次,以此往復,如果回答n或n,就退出程式 如何猜對了,就直接退出 import random 生成隨機數 n random.randint 0,200 允許使用者最多...

python 基礎(一)猜年齡遊戲

需求 1 可猜三次 2 三次猜完可選擇是否繼續 age of clyde 25count 0 while count 3 輸入預設是字串型別,轉換成int型別 age of int input age of clyde if age of age of clyde print 輸入的年齡為 age ...