I will share with you the answer to my core Python programming.
Because it is not from official resources, it is your own exercises. It may be wrong or not the best solution.
5-13.
Conversion. Write a function to convert the time represented by hours and minutes to the time represented by minutes.
[Answer]
The Code is as follows:
Def conversion (a, B ):
Return a * 60 + B
Time = raw_input ('Please input the time in HH: MM format :...')
T = time. split (':')
Print conversion (int (t [0]), int (t [1])
5-14.
Bank interest. Write a function with the time deposit rate as the parameter. If the account calculates compound interest on a daily basis, calculate and return the annual rate of return.
[Answer]
The Code is as follows:
DayInterestRate = float (raw_input ('Please input the day rate :...'))
Print (1. + dayInterestRate) ** 365-1
5-15.
The maximum common approx. Calculate the maximum common divisor and least common multiple of two integer types.
Background Knowledge]
The answer to this question uses the more-phase reduction technique, also known as the "equivalent algorithm", to calculate the maximum common divisor of two numbers, while the minimum common multiples of two numbers are their product divided by the maximum common divisor.
Least Common Multiple (LCM)
Greatest Common Divisor (GCD) or Highest Common Factor (HCF)
[Answer]
The Code is as follows:
Def GCD (a, B ):
I = 0
If (a % 2 = 0) and (B % 2 = 0 ):
C = a/2
D = B/2
I = I + 1
Else:
C =
D = B
While c! = D:
If c> d: c = c-d
Elif c <d: d = d-c
Else: return c * (2 ** I)
Return c * (2 ** I)
Def LCM (a, B ):
Return a * B/GCD (a, B)
Print GCD (4044,908 8)
Print LCM (4044,908 8)
[Reference] Algorithm for Finding the maximum public approx.
Http://blog.csdn.net/cauwtj/archive/2009/04/02/4043388.aspx
Four Methods for quickly finding the least common multiple
Http://www.hmtyxx.com/jiaoyu/ShowArticle.asp? ArticleID = 1414
Keywords: Pyhon core programming Second Edition answer unofficial