Python Level 2 Operation Problem Practice

# 1. Write a python program that inputs two numbers, compares their sizes and outputs the larger one.
num1 = input( ' Please enter the number X: ' )
num2 = input( ' Please enter the number Y: ' )
 if num1.isdecimal() and num2.isdecimal():
     if num1== num2:
         print ( ' The two numbers are the same ' )
     elif num1> num2:
         print ( ' %s is greater than %s ' % (num1,num2))
     else :
         print ( ' %s is less than %s ' % (num1,num2))
 else :
     print ( ' Number of numbers is wrong, exited ' )
View Code
# 2. Write an algorithm (flowchart and python program): input three numbers and output the largest one.
num1 = input( ' Please enter the first number >>> ' )
num2 = input( ' Please enter the second number >>> ' )
num3 = input( ' Please enter the third number >>> ' )
 if num1.isdecimal() and num2.isdecimal() and num3.isdecimal():
     print ( ' The maximum value of the three numbers is >>> ' + max(num1,num2,num3))
 else :
     print ( ' There are numbers that do not conform to the format ' )
View Code
# 3. Using Python programming, find the sum of all even numbers between 1 and 100 (including 100).
sum = 0
for num in range(101):
    if num %2 ==0:
        sum += num
 print (sum)
View Code
# 4. Write a program in Python, input a year, determine whether the year is a leap year and output the result.
year = int(input( ' Please enter the year >>> ' ))
 if year %4== 0:
     print ( ' This year is a leap year ' )
 else :
     print ( "A little bit " )
View Code
# 5. Using Python programming, assuming that the one-year fixed interest rate is 3.25%, how many years will it take to calculate how many years it will take to double the one-year fixed deposit of 10,000 yuan with principal and interest?
v = 3.25/100
v1 = 1+v
for i in range(999):
    if v1**i >= 2:
        print(i)
        break
View Code
# 6. Receive the 100-point scale (0~100) from the keyboard, and request to output the corresponding grades A~E. Among them, a score of 90 or more is 'A', 80-89 is 'B', 70-79 is 'C', 60-69 is 'D', and a score below 60 is 'E'.
score = int(input( ' Please enter the score>>> ' ))
 while True:
     if score>100 or score< 0:
         print ( ' The score must be a percentile! Out of range ' )
         break 
    elif score>=90 :
         print ( ' Your grade was judged as A ' )
         break 
    elif score >= 80 :
         print ( ' Your grade was judged as B ' )
         break 
    elif score >= 70 :
         print ( 'Your grade was judged as C ' )
         break 
    elif score >= 60 :
         print ( ' Your grade was judged as D ' )
         break 
    else :
         print ( ' Your grade was judged as E ' )
         break
View Code
# 7. Guessing game. Preset an integer between 0 and 9, let the user guess and enter the guessed number, if it is greater than the expected number, 
# display "too big"; less than the preset number, display "too small", and so on , until you guess the number, "Congratulations! You guessed it!" is displayed.
from random import *
num = int(random()*10)
while True:
    guess_num = int(input( ' Please enter a number >>> ' ))
     if guess_num> num:
         print ( ' too big ' )
     elif guess_num< num:
         print ( ' too small ' )
     else :
         print ( ' Congratulations! You guessed it right ' )
         break _
View Code
# 8. Input a number, determine whether the number is a prime number, and output the result. 
# (The so-called prime number refers to a number greater than 1 that is not divisible by any other integer except 1 and the number itself.)
#————————————————————— —————————————————————
# 9. Enter a time (hour:minute:second), and output the time after 5 minutes and 30 seconds.
#——————————————————————————————————————————
# 10. If a number is exactly Equal to the sum of its factors, this number is called "complete number".
# For example, the factors of 6 are 1, 2, 3, and 6=1+2+3, so 6 is the perfect number. Programming, find all the perfect numbers within 1000, and output the perfect numbers and the corresponding factors. (enumeration method)
#——————————————————————————————————————————
# 11 .Program to solve the monkey eating peach problem.
# The monkey picked a number of peaches on the first day, and immediately ate half of them, but it was not enough, so he ate another one. The next morning I ate half of the remaining peaches and ate one more.
# After that, I ate half and one leftover from the previous day every morning. By the 10th day when I wanted to eat it in the morning, there was only one peach left. Find how many peaches were picked on the first day. (Iterative method)
#—————————————————————————————————————————————
# 12. Write a python program that inputs two numbers and outputs the sum of the two numbers.
#—————————————————————————————————————————————


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325153242&siteId=291194637