Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the single Loop of Python full Stack

Shulou Source: shulou.com Published: 2022-06-02 09:20:28 09月29日 Update

This article introduces the relevant knowledge of "how to realize the single loop of Python full stack". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

1. Polyterm_Nested Branches

Multiple branches (multiple choice)

"""if conditional expression 1: code1 elif conditional expression 2: code2elif conditional expression 3: code3else: if conditional expression 1 is true, execute the corresponding branch code1; otherwise, judge whether conditional expression 2 is true; if conditional expression 2 is true, execute the corresponding branch code2; otherwise, judge whether conditional expression 3 is true; if conditional expression 3 is true, execute the corresponding branch code3; if not, directly take the else branch, elif can be 0 or more else can be 0 or one ""youqian = Falseyoufang = Falseyouche = Falseif youqian == True: print("This person is very powerful")elif youfang == True: print("Can I give it to a friend")elif youche == True: print("Open the Yadima transfer car, let's touch it") else: print("You'd better be a Meituan rider")print("")# ##nested branches "" Single branch, bidirectional branch, nested combination of multiple branches ""youqian = Truyoufang = Trueyouche = Trueyouyanzhi = Trueyoutili = Falseif youqian == True: if youfang == True: if youche == True: if youyanzhi == True: if youtili == True: print("I want to marry you ~") else: print("Go eat some big kidneys and come back ~") else: print("You go to Thailand + Korea, plastic surgery")else: print("You're a good person ~") print("")#question height#girl looking for a partner #Boys are between 1 meter and 1.5 meters. Xiaoqiang, where are you? #Boys don't feel safe between 1.5 and 1.7 meters ~ #Boys between 1.7 and 1.8 meters, handsome guys leave a phone number #Boys between 1.8~2 meters, handsome, do you suggest one more girlfriend # python unique (note: because input accepts strings, and because we enter decimals, we can only use float here)""height = float(input("please enter your height:"))if 1 i = 2 second loop i = 2 i total = total + i => 0 + 1 + 2i += 1 => i = 3 third loop i = 3 i total = total + i => 0 + 1 + 2 + 3 i += 1 => i = 4... And so on when i = 101 101 total + i => 0 + 1 + 2 + 3 + 4 +... + 100 => 5050"""#endless loop""while True: print(1)""# ####Use the endless loop method to realize 1 ~ 100 accumulation sum i = 1total = 0sign = Truewhile sign: total += i i+=1 #Determine if i is added to 101 , do not participate in the loop if i == 101: #End the cycle sign = Falseprint(total) #1 ~ 100 = 50502.2 Exercise for a single loop # (1) Print a line of ten small stars * help(print)# help View documentation for a method help(print)""# print ("*",end='')# print ("*",end='')# print ("*",end='')# print ("*",end='')# print("*",end='')# print("*",end='')# print("*",end='')# print("*",end='')# print("*",end='')# print("*",end='')"""i = 0while i

Tags: Character string index loop condition method number branch input result expression guess same code remainder number logic error output between Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB OPPO Reno Microsoft Huawei