In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use loop sentences in python". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to use loop sentences in python".
Loop statement
Multiple branches
Select process If-else statement
How to use a single branch to express a # if conditional expression; compare operators / logical operators or compound to express # code instructions # .score = 60if score60: print ('pass') passelse: print ('fail') pass
Multi-branch use of # multi-branch [multiple conditions] # if conditional expression; comparison operator / logical operator or compound expression # code instruction # elif conditional expression: # code instruction # elif conditional expression: # code instruction # else: # # actual situation can not be #. # # feature must satisfy one of them # as long as it satisfies one of the branches, it will exit the if statement structure # there are at least two cases where you can choose # elif and must follow the last condition # else is an option Choose score=int (input ('Please enter grades:) if score > 90: print (' your grades are excellent') pass elif score > 80: print ('good') pass elif score > 70: print ('medium') pass elif score > = 60: print ('qualified') pass else: print ('unqualified') pass
# Multi-branch Multi-condition drill # Boxing Game # 0 Stone 1 Scissors 2 Paper import random # Import Random number Module # computer person=int (input ('Please punch: [0 Stone 1 Scissors 2 Paper]) computer=random.randint (0pencil 2) if person==0 and computer==1: # Multi-conditional print (' you win....') Passelif person==1 and computer==2: print ('you won....') Passelif person==2 and computer==0: print ('you won....') Passelif person==computer: print ('not bad, tie') passelse: print ('lost.') Passprint ('Program execution complete')
# if-else nesting uses # to use in a scene needs to be staged or hierarchical Make different processing # to execute the internal conditional if statement, the external if statement must meet the conditions before xuefen=int (input ('Please enter your credits:') if xuefen > 10: grade = int ('Please enter your grades:') if grade > = 80: print ('you can be promoted') pass else: print ('I'm sorry Your grades are not up to standard') pass passelse: print ('your performance is too bad.')
While Loop # Loop Classification # while Syntax structure # while conditional expression: # Code instruction # Syntax Features # 1. The loop must have an initial value of # 2. Conditional expression # 3. Counting variables in the loop must increase and decrease themselves, otherwise it will result in an endless loop # Recycling scenario: the number of cycles is uncertain and depends on the loop conditions to end # purpose: to make similar or the same code operations more concise and convenient to reuse # for# while use # output data between 1-100 to define a variable while index
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.