当前位置:网站首页>【第5节 if和for】
【第5节 if和for】
2022-04-23 15:46:00 【qq_24409999】
第5节 if和for
if
"""if 测试登录用例 如果 用户名 = “yuze”: 登录成功 如果 用户名 = 空: 请输入用户名 否则: 登录失败 if 的 写法: if 条件表达式: (缩进) 条件满足会执行的程序 多行程序 条件表达式:要得到的值是一个bool类型,有一个条件 True ,False 如果条件成立,子代码块执行,如果不成立,:后面的子代码不执行 if : pass else: pass if (条件表达式): pass elif(条件表达式): pass elif(条件表达式): pass ... else; pass TODO:在同一个 if .... elif ...else 条件中,只要执行了其中一个分支,其他的分支就不会再执行了 TODO:但是,如果是不同的if if ...elif ...if... elif TODO:else 是可以省略 if :... TODO: if: if: if: else: pass """
#if ...elif...else...
username = "abc"
if username == "yuze" or username == "Demons":
#缩进表示条件满足以后我需要执行的子代码,是一个分支
print("登录成功")
elif username == "":
print("请输入用户名")
elif username =="Demons":
print("没有该用户")
else:
print("登录失败")
print("条件之后")
多个if
username = "abc"
password = ""
gender = "未知"
if username == "yuze":
print("用户名正确")
if password == "123456":
print("密码正确")
if gender == "男":
print("性别符合条件")
else:
print("性别不符合条件")
elif password =="":
print("密码为空")
else:
print("密码错误")
else:
print("用户名不正确")
#尽量避免多重嵌套
if username == "yuze" and password == "123456" and gender == "男":
print("登录成功")
elif username =="yuze" and password =="":
print("密码为空")
不是同一个if语句
#不是同一个if语句
username = "Demons"
if username == "yuze" or username == "Demons":
#缩进表示条件满足以后我需要执行的子代码,是一个分支
print("登录成功")
elif username == "":
print("请输入用户名")
if username =="Demons":
print("没有该用户")
else:
print("登录失败")
print("条件之后")
while循环
""" while 用的不是特别多 """
# username = ""
#
# while username =="yuze":
# print("hello world")
# print("finished")
#死循环
# username = ""
#
# while username !="yuze":
# print("hello world")
# #手工强制退出整个while循环
# break
# print("finished")
#
# username = ""
#
# while username !="yuze":
# print("hello world")
# #进入下一个循环,进入下次循环
# continue
# # print("continue 后面的代码不执行了")
# print("finished")
#
#double king
times = 0
while times <999:
print(f"我说了{
times}次")
print("我喜欢小文")
times = times+1
print("有钱人终成眷属")
for循环
"""for 我把所有的测试用例执行完 cases = [ {"username":"yuze","password":""}, {"username":"xianrenqiu","password":"123456"}, {"username":"","password":""} ] """
cases = [
{
"username":"yuze","password":""},
{
"username":"xianrenqiu","password":"123456"},
{
"username":"","password":""}
]
#把cases 当中的每个元素都执行一遍
#把值 {"username":"yuze","password":""},赋给case
#case是个变量
for case in cases:
#case = cases[0]
print(case)
print("正在执行用例")
#当for 循环执行完一个子循环以后
#隐含步骤,索引 index+=1
#通过调试去debug
#是暂停代码的运行去获取现在的数据状态
#打断点,告诉程序我应该在哪里暂停
for嵌套
a = [
["a","b","c"],
[1,2,3],
]
#嵌套列表
#先执行完内层 for 循环 ,再执行外层
# for i in a:
# for j in i:
# print(j)
#for 循环嵌套
li =[1,2,3,4,5,6]
for i in li:
for j in li:
print(f"{
i}*{
j}={
i*j}",end = "\t")
版权声明
本文为[qq_24409999]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_24409999/article/details/124309362
边栏推荐
- Spark 算子之partitionBy
- 新动态:SmartMesh和MeshBox的合作新动向
- c语言---指针进阶
- C#,贝尔数(Bell Number)的计算方法与源程序
- Control structure (I)
- One brush 313 sword finger offer 06 Print linked list from end to end (E)
- MySQL optimistic lock to solve concurrency conflict
- Timing model: gated cyclic unit network (Gru)
- Go concurrency and channel
- What role does the software performance test report play? How much is the third-party test report charged?
猜你喜欢
现在做自媒体能赚钱吗?看完这篇文章你就明白了
时序模型:门控循环单元网络(GRU)
新动态:SmartMesh和MeshBox的合作新动向
Advantages, disadvantages and selection of activation function
Spark 算子之partitionBy
mysql乐观锁解决并发冲突
Demonstration meeting on startup and implementation scheme of swarm intelligence autonomous operation smart farm project
CAP定理
Codejock Suite Pro v20. three
Spark 算子之sortBy使用
随机推荐
Node. JS ODBC connection PostgreSQL
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
Upgrade MySQL 5.1 to 5.611
布隆过滤器在亿级流量电商系统的应用
服务器中毒了怎么办?服务器怎么防止病毒入侵?
新动态:SmartMesh和MeshBox的合作新动向
多生成树MSTP的配置
Control structure (I)
Timing model: gated cyclic unit network (Gru)
Best practices of Apache APIs IX high availability configuration center based on tidb
Upgrade MySQL 5.1 to 5.68
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
JVM-第2章-类加载子系统(Class Loader Subsystem)
ICE -- 源码分析
一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
Code live collection ▏ software test report template Fan Wen is here
Spark 算子之filter使用
负载均衡器
Spark 算子之distinct使用
大型互联网为什么禁止ip直连