Re-learn Python, learn python
If statement Application -- calculate the maximum value
1 "2 calculate the maximum value among the three numbers, and print out 3" 4 a = int (input (":")) 5 B = int (input ("B:") 6 c = int (input ("c:") 7 8 if a> B: 9 max_num = a10 if max_num> c: 11 print (max_num) 12 else: 13 print (c) 14 else: 15 max_num = blob if max_num> c: 17 print (max_num) 18 else: 19 print (c) 20 21 print (max (a, B, c) # built-in function 22 print (min (a, B, c) # built-in Function
While Loop
Example 1: output an even number between 1 and 100-(but I think my program is stupid)
1 "2 output an even number between 1 and 100 3" 4 a = 0 5 while a <101: 6 for I in range (101 ): 7 if I % 2 = 0: 8 print (I) 9 I + = 110 if I> break12
Simplified:
A = 0 while a <101: if a % 2 = 0: print (a) a + = 1
Note: The while clause must be flase interrupted in the program, otherwise it will run endlessly.