1. 程式人生 > >跟隨Alex學習循環進階-猜年齡(純屬愛好,自己看自己的代碼都想吐...(⊙﹏⊙))

跟隨Alex學習循環進階-猜年齡(純屬愛好,自己看自己的代碼都想吐...(⊙﹏⊙))

pid closed num alex else == 技術 input \n

項目1:允許用戶最多猜三次,中間猜對了,直接跳出循環。

技術分享圖片
age = 56
count = 0

while count <= 2:
    count = count + 1
    input_number = input("please input your age")
    if int(input_number) != age:
        print("You are so stupid")
    if int(input_number) == age:
        print("You are so clever\nThe age is 56
") break
View Code

項目2:允許用戶猜三次,中間猜對了,直接跳出循環,沒有猜對詢問用戶是否還想玩,想玩繼續猜。

技術分享圖片
age = 44
count = 0
P = "Y"
while count <= 3:
    input_number = input("please input your age:")
    count +=1
    if int(input_number) == age:
        print("You are so clever,the age is right.")
        break
elif (count == 3) and int(input_number) != age: choice = input("The time is enough,please input your choice Y?orN") if choice ==P: count = 0 print("You are so obstinate") else: pass
View Code

跟隨Alex學習循環進階-猜年齡(純屬愛好,自己看自己的代碼都想吐...(⊙﹏⊙))