1.if-else

_username = 'heyue'
_password = '' username = input("username:")
password = input("password:") if username == _username and password == _password:
print("welcome user {name} login...".format(name=_username))
else:
print("invalid username or password")

2.if-elif-else

_age = 56
age = int(input("guess age:"))
if age == _age:
print("you got it")
elif age > _age:
print("think bigger")
else:
print("think smaller")

3.while  最多猜三次

_age = 56
count = 0
while count < 3:
age = int(input("guess age:"))
if age == _age:
print("you got it")
break
elif age > _age:
print("think bigger")
else:
print("think smaller")
count +=1
else:
print("you have tried too much times...")

4. for 最多猜三次

_age = 56
for i in range(3):
age = int(input("guess age:"))
if age == _age:
print("you got it")
break
elif age > _age:
print("think bigger")
else:
print("think smaller")
else:
print("you have tried too much times...")

5.猜三次后询问是否继续

_age = 56
count = 0
while count < 3:
age = int(input("guess age:"))
if age == _age:
print("you got it")
break
elif age > _age:
print("think bigger")
else:
print("think smaller")
count +=1
if count == 3:
countinue_confirm = input("do you want to keep guessing...")
if countinue_confirm != 'n':
count = 0

最新文章

  1. R语言读取本地文件注意事项
  2. express:webpack dev-server开发中如何调用后端服务器的接口?
  3. git ssh-add 报错 ssh-add Could not open a connection to your authentication agent
  4. android get uuid获取uuid
  5. oracle手动删除数据库
  6. null的小扩展
  7. hdu 4661 Message Passing(木DP&amp;amp;组合数学)
  8. JavaSE中Collection集合框架学习笔记(3)——遍历对象的Iterator和收集对象后的排序
  9. python 使用标准库根据进程名获取进程的pid
  10. 应用fstream格式化输出
  11. LeetCode算法扫题系列83
  12. [转]VC++宏与预处理使用方法总结
  13. Windows 安装 docker 以及1709的简单使用
  14. gitlab访问用户安装的postgresql数据库
  15. js设计模式总结3
  16. redis该怎么用
  17. VS未能正确加载 ”Microsoft.VisualStudio.Editor.Implementation.EditorPackate“包错误解决方法
  18. Magento2开发教程 - 如何向数据库添加新表
  19. void与NULL详解
  20. 把MacBook里的电影导入到iPad

热门文章

  1. 物流跟踪API-快递单订阅
  2. 【搞定面试官】- Synchronized如何实现同步?锁优化?(1)
  3. 详解python的装饰器decorator
  4. 用MYSQL的存储过程创建百万级测试数据表
  5. SpringBoot Jpa 自定义查询
  6. 动手学习Pytorch(7)--LeNet
  7. 2020年,手把手教你如何在CentOS7上一步一步搭建LDAP服务器的最新教程
  8. 安装ik分词插件
  9. Rust学习--变量
  10. pycharm创建Django项目时报 AttributeError:&#39;module&#39; object has no attrbute &#39;main&#39; 错误或者创建了就只有venv一个目录