猜数字2019-03-17
2019-03-17 本文已影响0人
swagsmile
1.让用户输入1-20,猜数字,可以猜5次。
2.每次有提示,大了,或者小了!
3.如果超过5次,提示game over.
备注:老鸟记得加一些异常处理,在input的地方"""
LimitTimes=5
i=0
RightNum = 15
while i < LimitTimes:
try:
num = int(input("Please input the correct num which beteween 1-20:"))
if num < RightNum:
print("too small!")
elif num > RightNum:
print("too large!")
elif num == RightNum:
print("Bingo!")
i+= 1
except ValueError:
print("You should input the right type num.")
#print(num)
else:
print("Game Over!")