tutu小白python-day2---if..while..for
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了tutu小白python-day2---if..while..for,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1790字,纯文字阅读大概需要3分钟。
内容图文
![tutu小白python-day2---if..while..for](/upload/InfoBanner/zyjiaocheng/831/9700a146655d46be8dc3550db6d6bdf8.jpg)
if 判断
定义变量age=25,如果输入小于25 print you are thinks bigger
大于25 print you are thiks smaller
等于25则print you are git
name =input("name:")
age =25
tutuage =int(input("tutuage:"))
if age == tutuage:
print ("you are git")
elif age >tutuage:
print ("you are thinks bigger")
else:
print("thinks smaller")
while循环 一直循环,直到对了跳出循环
age = 25
count =0
while True:
tutuage =int(input("tutuage:"))
if age == tutuage:
print ('this is git')
break
elif age > tutuage:
print ('you are thinks bigger')
else:
print ('you are thinks smaller')
count +=1
while 定义循环次数
如果正确则跳出循环,如果输入错误5次也跳出循环
age =25
count =0
while True:
tutuage =int(input("tutuage:"))
if age == tutuage:
print ('ok')
break
if count ==4:
break
count +=1
猜测年龄,做多三次,对了跳出循环,三次不对也跳出循环print you get fuck off
age =25
count =0
while count <3:
tutuage =int(input("tutuage:"))
if age == tutuage:
print ('this is git')
break
elif age > tutuage:
print ('you are thinks bigger')
else:
print ('you are thinks smaller')
count +=1
else:
print ('you get fuck off')
for 循环使用
for i in range(3):
print ('qiqi',i)
结果如下:
qiqi 0
qiqi 1
qiqi 2
用for实现上边的猜测年龄,正确跳出,错误三次跳出
age =25
for i in range(3):
tutuage =int(input("tutuage:"))
if age == tutuage:
print ('this is git')
break
elif age > tutuage:
print ('you are thinks bigger')
else:
print ('YOU ARE THINKS SMALLER')
else:
print ('you get fuck off')
如果三次都不对,按回车键继续,n键退出
age =25
count =0
while count <3:
tutuage =int(input("tutuage:"))
if age == tutuage:
print ('this is git')
break
elif age > tutuage:
print ('you are thinks bigger')
else:
print ('you are thinks smaller')
count +=1
if count ==3:
countine_confirm =input ('do you want guee keep...')
if countine_confirm != 'n':
count =0
小结:
continue 跳出本次循环,继续下次循环
break 结束整个循环
内容总结
以上是互联网集市为您收集整理的tutu小白python-day2---if..while..for全部内容,希望文章能够帮你解决tutu小白python-day2---if..while..for所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。