码迷,mamicode.com
首页 > 编程语言 > 详细

python之猜数字

时间:2019-02-24 10:45:00      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:guess   input   number   python   you   NPU   ber   try   erro   

使用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


python之猜数字

标签:guess   input   number   python   you   NPU   ber   try   erro   

原文地址:https://www.cnblogs.com/chenrjfight/p/10425385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!