使用python实现当猜数字,当数字大了,提示数字大,数字小了提示数字小,如果3次猜错,询问是否继续猜
使用while循环来实现代码如下
num=56
count=0
while count<=2:
guess=input('enter your guessing number:')
if guess.isdigit():
guess=int(guess)
if guess==num:
print('congratulations!')
break
elif guess>=num:
print('think smaller!')
else:
print('think bigger!')
else:
print('error!')
count+=1
if count==3:
answer=input('would your like to try again?(Y/N)')
if answer=='Y':
count=0
else:
break