当前位置:网站首页>【第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
边栏推荐
猜你喜欢
![[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention](/img/bf/2b4914276ec1083df697383fec8f22.png)
[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention

IronPDF for .NET 2022.4.5455

cadence SPB17.4 - Active Class and Subclass

MySQL集群模式與應用場景

王启亨谈Web3.0与价值互联网“通证交换”

Application of Bloom filter in 100 million flow e-commerce system

pgpool-II 4.3 中文手册 - 入门教程

Redis master-slave replication process

Recommended search common evaluation indicators
![Merging of Shanzhai version [i]](/img/e7/f301697aea879bcad8cef70ca890cc.png)
Merging of Shanzhai version [i]
随机推荐
删除字符串中出现次数最少的字符
What if the server is poisoned? How does the server prevent virus intrusion?
基础贪心总结
[split of recursive number] n points K, split of limited range
Config组件学习笔记
Node. JS ODBC connection PostgreSQL
Today's sleep quality record 76 points
Recommended search common evaluation indicators
Demonstration meeting on startup and implementation scheme of swarm intelligence autonomous operation smart farm project
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
移动金融(自用)
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
Codejock Suite Pro v20.3.0
pywintypes. com_ Error: (- 2147221020, 'invalid syntax', none, none)
Upgrade MySQL 5.1 to 5.66
One brush 313 sword finger offer 06 Print linked list from end to end (E)
utils.DeprecatedIn35 因升级可能取消,该如何办
Accumulation of applet knowledge points
使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群
一刷313-剑指 Offer 06. 从尾到头打印链表(e)