当前位置:网站首页>[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
边栏推荐
猜你喜欢

Spark 算子之sortBy使用

Recommended search common evaluation indicators

Multitimer V2 reconstruction version | an infinitely scalable software timer

时序模型:长短期记忆网络(LSTM)

Why disable foreign key constraints

网站建设与管理的基本概念

Mumu, go all the way

New developments: new trends in cooperation between smartmesh and meshbox

Cap theorem

Neodynamic Barcode Professional for WPF V11. 0
随机推荐
Codejock Suite Pro v20.3.0
考试考试自用
Control structure (I)
北京某信护网蓝队面试题目
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
Named in pytoch_ parameters、named_ children、named_ Modules function
pgpool-II 4.3 中文手册 - 入门教程
【第5节 if和for】
Temporal model: long-term and short-term memory network (LSTM)
mysql乐观锁解决并发冲突
WPS品牌再升级专注国内,另两款国产软件低调出国门,却遭禁令
What if the server is poisoned? How does the server prevent virus intrusion?
shell_2
CVPR 2022 优质论文分享
What if the package cannot be found
Go language slice, range, set
leetcode-374 猜数字大小
Configuration of multi spanning tree MSTP
Mobile finance (for personal use)
负载均衡器