python学习随笔2:python判断和循环
2024-09-06 12:42:36
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
最新文章
- R语言读取本地文件注意事项
- express:webpack dev-server开发中如何调用后端服务器的接口?
- git ssh-add 报错 ssh-add Could not open a connection to your authentication agent
- android get uuid获取uuid
- oracle手动删除数据库
- null的小扩展
- hdu 4661 Message Passing(木DP&;amp;组合数学)
- JavaSE中Collection集合框架学习笔记(3)——遍历对象的Iterator和收集对象后的排序
- python 使用标准库根据进程名获取进程的pid
- 应用fstream格式化输出
- LeetCode算法扫题系列83
- [转]VC++宏与预处理使用方法总结
- Windows 安装 docker 以及1709的简单使用
- gitlab访问用户安装的postgresql数据库
- js设计模式总结3
- redis该怎么用
- VS未能正确加载 ”Microsoft.VisualStudio.Editor.Implementation.EditorPackate“包错误解决方法
- Magento2开发教程 - 如何向数据库添加新表
- void与NULL详解
- 把MacBook里的电影导入到iPad
热门文章
- 物流跟踪API-快递单订阅
- 【搞定面试官】- Synchronized如何实现同步?锁优化?(1)
- 详解python的装饰器decorator
- 用MYSQL的存储过程创建百万级测试数据表
- SpringBoot Jpa 自定义查询
- 动手学习Pytorch(7)--LeNet
- 2020年,手把手教你如何在CentOS7上一步一步搭建LDAP服务器的最新教程
- 安装ik分词插件
- Rust学习--变量
- pycharm创建Django项目时报 AttributeError:&#39;module&#39; object has no attrbute &#39;main&#39; 错误或者创建了就只有venv一个目录