当前位置:网站首页>[section 5 if and for]
[section 5 if and for]
2022-04-23 15:48:00 【qq_ twenty-four million four hundred and nine thousand nine hun】
The first 5 section if and for
if
"""if Test login cases If user name = “yuze”: Login successful If user name = empty : Please enter a user name otherwise : Login failed if Of How to write it : if Conditional expression : ( Indent ) The program that will be executed when the conditions are met Multiline program Conditional expression : The value to be obtained is a bool type , There is one condition True ,False If the condition holds , Sub code block execution , If not ,: The following subcode does not execute if : pass else: pass if ( Conditional expression ): pass elif( Conditional expression ): pass elif( Conditional expression ): pass ... else; pass TODO: In the same if .... elif ...else In the condition , As long as one of the branches is executed , Other branches will no longer be executed TODO: however , If it's different if if ...elif ...if... elif TODO:else You can omit if :... TODO: if: if: if: else: pass """
#if ...elif...else...
username = "abc"
if username == "yuze" or username == "Demons":
# Indentation indicates the sub code I need to execute after the conditions are met , It's a branch
print(" Login successful ")
elif username == "":
print(" Please enter a user name ")
elif username =="Demons":
print(" There is no such user ")
else:
print(" Login failed ")
print(" After the condition ")
Multiple if
username = "abc"
password = ""
gender = " Unknown "
if username == "yuze":
print(" The user name is correct ")
if password == "123456":
print(" The password is correct ")
if gender == " male ":
print(" Gender meets the requirements ")
else:
print(" Gender does not qualify ")
elif password =="":
print(" The password is empty. ")
else:
print(" Wrong password ")
else:
print(" Incorrect user name ")
# Try to avoid multiple nesting
if username == "yuze" and password == "123456" and gender == " male ":
print(" Login successful ")
elif username =="yuze" and password =="":
print(" The password is empty. ")
Not the same if sentence
# Not the same if sentence
username = "Demons"
if username == "yuze" or username == "Demons":
# Indentation indicates the sub code I need to execute after the conditions are met , It's a branch
print(" Login successful ")
elif username == "":
print(" Please enter a user name ")
if username =="Demons":
print(" There is no such user ")
else:
print(" Login failed ")
print(" After the condition ")
while loop
""" while It's not very much """
# username = ""
#
# while username =="yuze":
# print("hello world")
# print("finished")
# Dead cycle
# username = ""
#
# while username !="yuze":
# print("hello world")
# # Manually force the exit of the whole while loop
# break
# print("finished")
#
# username = ""
#
# while username !="yuze":
# print("hello world")
# # Enter the next cycle , Into the next loop
# continue
# # print("continue The following code is not executed ")
# print("finished")
#
#double king
times = 0
while times <999:
print(f" Have I said {
times} Time ")
print(" I like Xiaowen ")
times = times+1
print(" The rich get married ")
for loop
"""for I finished all the test cases cases = [ {"username":"yuze","password":""}, {"username":"xianrenqiu","password":"123456"}, {"username":"","password":""} ] """
cases = [
{
"username":"yuze","password":""},
{
"username":"xianrenqiu","password":"123456"},
{
"username":"","password":""}
]
# hold cases Each of these elements is executed once
# Set value {"username":"yuze","password":""}, Assign to case
#case It's a variable
for case in cases:
#case = cases[0]
print(case)
print(" Executing use case ")
# When for After the loop executes a sub loop
# Implicit steps , Indexes index+=1
# Go through debugging debug
# Is to pause the running of the code to get the current data state
# Breaking point , Tell the program where I should pause
for nesting
a = [
["a","b","c"],
[1,2,3],
]
# Nested list
# Finish the inner layer first for loop , Then execute the outer layer
# for i in a:
# for j in i:
# print(j)
#for A nested loop
li =[1,2,3,4,5,6]
for i in li:
for j in li:
print(f"{
i}*{
j}={
i*j}",end = "\t")
版权声明
本文为[qq_ twenty-four million four hundred and nine thousand nine hun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231545518326.html
边栏推荐
- WPS品牌再升级专注国内,另两款国产软件低调出国门,却遭禁令
- 贫困的无网地区怎么有钱建设网络?
- MySQL集群模式与应用场景
- How do you think the fund is REITs? Is it safe to buy the fund through the bank
- WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
- MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
- 布隆过滤器在亿级流量电商系统的应用
- Config组件学习笔记
- 时序模型:门控循环单元网络(GRU)
- Independent operation smart farm Innovation Forum
猜你喜欢
One brush 314 sword finger offer 09 Implement queue (E) with two stacks
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
c语言---字符串+内存函数
布隆过滤器在亿级流量电商系统的应用
网站压测工具Apache-ab,webbench,Apache-Jemeter
MySQL集群模式与应用场景
MySQL集群模式與應用場景
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
【AI周报】英伟达用AI设计芯片;不完美的Transformer要克服自注意力的理论缺陷
Basic concepts of website construction and management
随机推荐
[AI weekly] NVIDIA designs chips with AI; The imperfect transformer needs to overcome the theoretical defect of self attention
大型互联网为什么禁止ip直连
Fastjon2 here he is, the performance is significantly improved, and he can fight for another ten years
Modèle de Cluster MySQL et scénario d'application
Mobile finance (for personal use)
新动态:SmartMesh和MeshBox的合作新动向
String sorting
Multitimer V2 reconstruction version | an infinitely scalable software timer
为啥禁用外键约束
JVM-第2章-类加载子系统(Class Loader Subsystem)
【自娱自乐】构造笔记 week 2
c语言---字符串+内存函数
Upgrade MySQL 5.1 to 5.611
gps北斗高精度卫星时间同步系统应用案例
Partitionby of spark operator
MySQL集群模式與應用場景
What if the package cannot be found
建设星际计算网络的愿景
cadence SPB17. 4 - Active Class and Subclass
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)