博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python if/while/fo条件判断
阅读量:5090 次
发布时间:2019-06-13

本文共 2337 字,大约阅读时间需要 7 分钟。

判断3次,猜年龄

方法一

1 # author = "zhuyouen" 2 age_of_zhuyouen = 35 3  4 count = 0 5 while count < 3: 6     guess_age = int(input("age:")) 7     if age_of_zhuyouen == guess_age: 8         print("age is ok") 9         break10     elif age_of_zhuyouen > guess_age:11         print("age is small")12     else:13         print("age in large")14     count +=115 else:16     print("you have test too many times,fuck off..")
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/guess.pyage:35age is ok

方法二

1 # author = "zhuyouen" 2 age_of_zhuyouen = 35 3  4 for i in range(3): 5     guess_age = int(input("age:")) 6     if age_of_zhuyouen == guess_age: 7         print("age is ok") 8         break 9     elif age_of_zhuyouen > guess_age:10         print("age is small")11     else:12         print("age in large")13 else:14     print("you have test too many times,fuck off..")
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/guess_for.pyage:23age is smallage:23age is smallage:35age is ok

方法三

1 # author = "zhuyouen" 2 age_of_zhuyouen = 35 3  4 count = 0 5 while count < 3: 6     guess_age = int(input("age:")) 7     if age_of_zhuyouen == guess_age: 8         print("age is ok") 9         break10     elif age_of_zhuyouen > guess_age:11         print("age is small")12     else:13         print("age in large")14     count +=115     if count == 3:16         confirm_input = input("do you want input guess again..")17         if confirm_input != "quit":18             count = 0
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/guess任意.pyage:1age is smallage:1age is smallage:1age is smalldo you want input guess again..quit

 

自增加10

1 # author = "zhuyouen" 2  3 count = 0 4 while True: 5     print("count:",count) 6     count +=1 7     if count == 10: 8         break 9 10 11 12 #for i in range(10):13 #    print("loop",i)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/while.pycount: 0count: 1count: 2count: 3count: 4count: 5count: 6count: 7count: 8count: 9
1 # author = "zhuyouen" 2 ''' 3 count = 0 4 while True: 5     print("count:",count) 6     count +=1 7     if count == 10: 8         break 9 '''10 11 12 for i in range(10):13     print("loop",i)
D:\python35\python.exe D:/PycharmProjects/zhuyouen/0324/while.pyloop 0loop 1loop 2loop 3loop 4loop 5loop 6loop 7loop 8loop 9

 

转载于:https://www.cnblogs.com/zhuyouen/p/6658862.html

你可能感兴趣的文章
everything 快速搜索有代价
查看>>
Spark RDD概念学习系列之如何创建RDD
查看>>
SQL Server 2008 R2 企业版安装教程
查看>>
DroDownList控件多级下拉菜单
查看>>
js 与 数列
查看>>
awk实用技巧
查看>>
Python-1写Python程序的头
查看>>
HTML(7)图像、背景和颜色
查看>>
openstack pike 使用 linuxbridge + vxlan
查看>>
vim 括号匹配 以及各种跳转技巧
查看>>
正在学习或准备学习 Web 应用开发的初学者
查看>>
各大公司架构实践聚合
查看>>
linq中group by 的用法
查看>>
西安前端交流会 - 【前端求职、就业、面试技巧】- 第5期-2015.3.29 报名了
查看>>
Linux-进程间通信(四): 域套接字
查看>>
jq check 复选变单选。
查看>>
C#父类子类对象关系
查看>>
(转)RACI模型(RACI Model)
查看>>
关于&&和||
查看>>
HTML5 学习笔记(一)——HTML5概要与新增标签
查看>>