In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly talks about "what is the structure of python loop". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the structure of the python loop?"
1. Find the greatest common divisor of two numbers num1 = int (input ('please enter the first number:') num2 = int (input ('please enter the second number:') max_num = max (num1, num2) min_num = min (num1, num2) r = max_num% min_numwhile r! = 0: max_num = min_num min_num = r = max_num% min_numprint (num1, "and", num2, "the greatest common divisor is" Min_num) 2. Integer reversal: such as 12345 Output 54321#1num1 = input ('Please enter a number:') lenth = len (num1) a = [] for i in num1: a.append (I) a.reverse () # reverse the list str1 =''for i in a: str1 + = iprint (int (str1)) # 2number_new=num1 [::-1] # slice print (number_new) # 3new_num = 0num1 = int (num1) while num1: # the remainder of num1 The first loop calculates the variable last = num1% 10 # new_num, putting last in individual bits for the first time, and ten places for the second time, increasing in turn. New_num = new_num * 10 + last # round off the num1 to ensure that the next bit is taken out in the next loop and the integer sum between num1=num1 / / 10print (new_num) 3 and 1: 10 is guaranteed. Get the current number for i in range (21): for j in range (21): if ionomj > 20 and c: print ('{} + {} = {} '.format) 4, enter the daily study time (in hours) from Monday to Friday, and calculate the average daily study time. B = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] sum = 0for i in range (5): a = int (input (study time of f'{b [I]}:') sum + = apingjun = sum / 5print ("average study time:", pingjun) 5, output a complete number of less than 10000
If a positive integer is equal to the sum of all divisors except itself, it is called a complete number.
For example, 6 is the first perfect number, because 6, 1, 2, 3.
For i in range (1 for j in range 1000): sum = 1 for j in range (1 Magi): if I% j = 0: sum + = j if sum = = I: print (f "{I} is a complete number") 6, users play games
Each time you play 5 games (the results are shown below) (1) less than 5 games cannot be promoted. (2) in 5 games, if 80% reaches more than 80 points, it is level 1, and if 60% reaches 80 points or more, it is level 2, otherwise it cannot be promoted.
C = [] a = int (input ('you are playing the first inning, the score is:') c.append (a) for i in range (4): B = input ('continue to play (yline n):') if b ='y play: print ('play the next round') a = int (input (f 'you are playing the first round, score:') c.append (a) else: print ('I'm sorry You failed to finish the game') breaksum = 0for i in c: if I > = 80: sum + = 1if sum / len (c) > = 0.8: print ('level 1') elif sum / len (c) > = 0.6: print ('level 2') else: print ('cannot be promoted') 7, automatic menu loop
As long as you do not enter 3, cycle welcome to the xxx system 1 login 2 registration 3 exit please select: 1 login
A = Truewhile a: print ('Welcome to the student management system') print ('1 login 2 register 3 exit') num = int ('please select:') if num = 3: print ("exit system") a = False elif num = = 1: print ('Congratulations on login') elif num = = 2: print ('Congratulations on registration') 8, print graphics
one
twenty-one
three hundred and twenty one
4321
54321
654321
For i in range (1B7): for j in range (I): print (iMuj enduring cycles') print () so far, I believe you have a better understanding of "what is the structure of python loops". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 217
*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.