使用python实现当猜数字,当数字大了,提示数字大,数字小了提示数字小,如果3次猜错,询问是否继续猜
使用while循环来实现代码如下
num=56count=0while 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
原文地址:https://www.cnblogs.com/chenrjfight/p/10425385.html
时间: 2024-10-04 03:48:27