当前位置:网站首页>Small test (I)

Small test (I)

2022-07-26 03:07:00 Programmer Haozi

Catalog

The main points of this issue :

The content of this issue :   

The first question is :

The second question is : 

Third question : 

  Summary :


The main points of this issue :

      We have learned a lot in previous issues , In this issue, let's examine , Here I have prepared three small questions , As long as you look carefully in front, you can make it , Try the current screen !!!

The content of this issue :   

The first question is :

        subject : It's today 2022 year 7 month 25 Japan , Then we write it as a time integer, which is :2022725, Here we need to calculate its year separately 、 month 、 Japan

        Ideas : stress the essentials :2022725        Using calculation , So what is calculation ? That's addition 、 Subtraction 、 Multiplication 、 division 、 to be divisible by 、 Take several of them to write this question

        I believe you must have your own answer , Then let's solve it :

  Source code :

Date = 2022725
Year = Date // 1000     #  Get by divising 2022
Month = Date // 100 %10 #  Get by dividing and remainder 7
Day = Date % 100        #  Get... By taking the remainder 25
#  Print the results :
print(Year)
print(Month)
print(Day)

Print the results :

The second question is : 

         subject : take Hello、Python These two words are spliced together .

        Ideas :  Still focus on key points :“ word ” It is determined that this is a string type         “ Splicing ” That is, put them together         therefore : The test point of this question is the splicing of strings .

         I believe you must have your own answer , Then let's solve it :

Source code :

str1 = 'Hello'  #  First assign the first value 
str2 = 'Python' #  Assign the second value 

#  The first one is :
#  String formatting splicing 
print('%s %s' % (str1,str2))

#  The second kind :
# join Method splicing 
print(' '.join([str1,str2]))

#  The third kind of :
# format Method splicing 
print('{} {}'.format(str1,str2))

#  A fourth :
# format Abbreviation splicing 
print(f'{str1} {str2}')

Print the results :

Third question : 

        subject : Let the user provide the radius , Then calculate the circumference and area of the corresponding circle ( Keep two decimal places at the end )

        Ideas : Focus on the key points : The user provides , Use our input Built in functions           And it needs the help of mathematical modules to obtain the PI         Understand the formula of circle circumference and area         Keep two decimal places , You can use string formatting and high-precision modules

         I believe you must have your own answer , Then let's solve it :

Source code :

#  Import math module 
import math
#  Import high-precision modules 
import decimal

#  Let the user provide the radius of the circle 
r = int(input(" Please enter the radius of the circle :"))
#  Get the pi 
pi = math.pi

#  The perimeter formula ( High precision )
C = decimal.Decimal(r) * decimal.Decimal(2) * decimal.Decimal(pi)
#  Area formula ( High precision )
S = decimal.Decimal(r) ** decimal.Decimal(2) * decimal.Decimal(pi)

#  Print the perimeter with two decimal places 
print('%.2f' % C)
#  Print the area with two decimal places 
print('%.2f' % S)

Print the results ( Take the radius as 5 To test ):

  Summary :

        In this issue, we practiced three small problems , I hope I can help you !!!

原网站

版权声明
本文为[Programmer Haozi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/207/202207260302082767.html