'''
需求:
一、可猜三次
二、三次猜完可選擇是否繼續
'''
age_of_Clyde = 25
count = 0while count < 3: #輸入默認是字符串類型,轉換成int類型 age_of = int(input('age_of_Clyde:')) if age_of == age_of_Clyde : print('輸入的年齡爲:',age_of,'\n正確') break #跳出循環;continue 爲跳出單次循環,繼續下一次循環 elif age_of > age_of_Clyde: print('輸入的年齡爲【%s】大於實際年齡'%(age_of)) else: print('輸入的年齡爲【%s】小於實際年齡'%(age_of)) count +=1 if count ==3: age = input('輸入n繼續,不然退出') if age != 'n': print('遊戲結束') break else: count = 0