<>Python Basic exercises ( One )

* Give me a radius , Finding the area and perimeter of a circle . PI is 3.14 # Give me a radius , Finding the area and perimeter of a circle . PI is 3.14 r = float(input(" Please enter the radius of the element :")
) print(f" The area of the circle is :{3.14*r**2}, The circumference of yuan is :{2*3.14*r}")
* Enter two numbers , After comparing sizes , Printing in ascending order from small to large # Enter two numbers , After comparing sizes , Printing in ascending order from small to large num1 = int(input(" Please enter the first number :"))
num2= int(input(" Please enter the second number :")) if num1 < num2: print(num1,num2) else: print(num2,
num1)
*
Enter a score , Judge students' grades ,A to E, among ,90 The above points are ’A’,80-89 Divided into ‘B’,70-79 Divided into ‘C’,60-69 Divided into ‘D’,60 Divided into ‘E’
# Enter a score , Judge students' grades ,A to E, among ,90 The above points are 'A',80-89 Divided into ‘B’,70-79 Divided into ‘C’,60-69 Divided into ‘D’,60 Divided into ‘E’
booll= True while booll: try: score = int(input(" Please input the result :")) booll = False except:
print(" Wrong input data !") if score >= 80 : if score >=90: print(" Grades :A") else: print(
" Grades :B") elif score >= 60: if score >= 70: print(" Grades :C") else: print(" Grades :D"
) else: print(" Grades :E")
* input 2 A number , Maximum output # input 2 A number , Maximum output num1 = int(input("Num1=")) num2 = int(input(
"Num2=")) print(num1 if num1-num2 >0 else num2)
* Given a 5 Positive number of digits , How many of them are there # Given a 5 Positive number of digits , How many of them are there num3 = int(input("num3=")) print(
len(str(num3))," digit ")
* Dead cycle input number , After input, print out the maximum value and the average number of all the previous numbers , If the input is not a number , It is quit String or space , Then the cycle ends , Exit the program .
# Dead cycle input number , After input, print out the maximum value and the average number of all the previous numbers , If the input is not a number , It is quit String or space , Then the cycle ends , Exit the program . boolt =
True numSum = 0 count = 0 numMax = None while boolt: num = input(
" please enter a number ( Spaces or quit sign out ):") if num == " " or num.lower() == "quit" : break; try: num =
int(num) if not count: numMax = num elif numMax < num: numMax = num numSum +=
num count+= 1 print(f" The maximum value is :{numMax}\t The average value is :{float(numSum)/count}") except: print(
" Wrong input data !") continue
* use * Print a side length of n Square of ,n Is an integer . # use * Print a side length of n Square of ,n Is an integer . boole = True while
boole: try: n = int(input(" Please input the side length of the square :")) boole = False for i in range(n): for k
in range(n): print("*",end=" ",sep=""); print(sep=""); except: print(" Wrong input ");
* Enter a positive integer n, seek 0 To all within this number Sum of odd numbers And Sum of even numbers . # Enter a positive integer n, seek 0 To all within this number Sum of odd numbers And Sum of even numbers . boole =
True while boole: try: n = int(input(" Please enter a positive integer :")) boole = False odd = 0 # even numbers
even= 0 # Odd number for i in range(n): if i & 1: odd += i else: even += i print(f
" Odd sum :{odd}, Even sum :{even}") except: print(" Wrong input ");
* seek 1 reach 5 Factorial results of # seek 1 reach 5 Factorial results of num = 5 factorial = 1 for i in range(1,num+1):
factorial*=i print(f"{i} The factorial of is :{factorial}")
* Enter an integer , Judge whether he is a prime . # Enter an integer , Judge whether he is a prime . num = int(input(" Please enter an integer :")) if(num<2):
print(f"{num} It's not a prime ") elif num==2: print(f"{num} It's a prime ") else: for i in range(2,int(
num**0.5+2)): if not num%i : break else: print(f"{num} It's a prime ") print(f"{num} It's not a prime ")

Technology