python 使用while写猜年龄小游戏过程解析
2019-10-07 10:12
986 查看
需求:
用户一轮有三次机会进行猜年龄游戏,每猜一次会给相应的提示告知用户应该往大点猜或者小点猜,三次机会用完以后,可选择重新再来三次机会。
思路:
首先定义一个初始年龄为25和初始次数0,然后每猜一次,次数加1,同时提示猜的年龄是太小或者太大,猜对时退出游戏,当次数等于3时,提示用户是否重新再来。
代码如下:
age_of_fww = 25 count = 0 while count < 3: guess_age = int(input("guess_age:")) if guess_age == age_of_fww: print("yes! you got it") break elif guess_age < age_of_fww: print("think bigger!") else: print("think smaller!") count+=1 if(count == 3): continue_confirm = input("do you want to keep guessing(y/n)") if continue_confirm == 'y': count = 0
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- Python 使用 docopt 解析json参数文件过程讲解
- 使用Python给头像戴上圣诞帽的图像操作过程解析
- Python使用grequests(gevent+requests)并发发送请求过程解析
- 解析Python中while true的使用
- 全面解析Python的While循环语句的使用方法
- Python使用scrapy爬取阳光热线问政平台过程解析
- python2使用bs4爬取腾讯社招过程解析
- Python使用Beautiful Soup爬取豆瓣音乐排行榜过程解析
- QML使用Python的函数过程解析
- 解析Python中while true的使用
- 全面解析Python的While循环语句的使用方法
- Python使用mongodb保存爬取豆瓣电影的数据过程解析
- 黄聪:使用Python中的urlparse、urllib抓取和解析网页(一)
- python-使用正则快速解析QQ群聊记录
- 使用python解析json文件
- 使用python解析xml成对应的html示例分享
- 使用Selenium2 Python实现网页登陆过程
- 使用python的lxml解析html
- python_getopt解析命令行输入参数的使用
- python使用imap接收邮件的过程...郁闷的探索