猜年齡遊戲,允許用戶猜三次,三次過後,問用戶是否還想玩,輸入y則繼續,以此往復:
環境:Pycharm,Python3.7
i=0
age=22
while i < 3:
guss=int(input("guss how old am i:"))
if guss == age:
print("yep!")
elif guss < age:
print("Too young")
i=i+1
elif guss > age:
print("Too old")
i+=1
if i == 3:
choose=input("Do you want to try again?")
if choose == 'y':
i=0
continue
else:
break