跟隨Alex學習循環進階-猜年齡(純屬愛好,自己看自己的代碼都想吐...(⊙﹏⊙))
阿新 • • 發佈:2019-03-03
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 56View Code") break
項目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.") breakView Codeelif (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
跟隨Alex學習循環進階-猜年齡(純屬愛好,自己看自己的代碼都想吐...(⊙﹏⊙))