Strength of python every day (by analogy)

Examples of python strength every day (by analogy)

Example 1:

365 days a year, the ability to base the value on day 1, referred to as 1.0, the ability to learn when the previous day values ​​increased by 0.1% with no real ability to learn values ​​the previous day decreased 0.1%.

Q: hard every day and indulge every day, how much difference does a year down?

Analysis: Every day upward force = (1 + 0.001) ^ 365, every day faire force = (1 to 0.001) ^ 365

code:

. 1  # DayDayUp1.py storage file name 
2  Import Math
 . 3 dayup Math.pow = ((1.0 + from 0.001), 365) # increase from 0.001 
. 4 daydown Math.pow = ((of 1.0 to 0.001), 365) # faire from 0.001 
. 5  Print ( " down: {:. 2f}, down: {} :.. 2F. " .format (dayup, daydown))

operation result:

Down: 1.44, down: 0.69.

Example 2:

If examples of efforts to increase the value of 1 instead of 0.5%, 1% of it?

Analysis: The daily factors efforts will be constantly changing according to different needs, so you can define a new code dayfactor variable represents the value; so that every time change by simply changing dayfactor variable value.

code:

. 1  Import Math
 2 dayfactor = 0.005
 . 3 dayup Math.pow = ((1.0 + dayfactor), 365) # improve 0.005 
. 4 daydown Math.pow = ((1.0-dayfactor), 365) # faire 0.005 
. 5  Print ( " Down: {: .2f}, down:. {. 2F} :. " .format (dayup, daydown))

operation result:

Down: 6.17, down: 0.16.

Example 3:

The week days efforts, increased by 1%; only two days of weekend indulgence, the ability value decreased by 1%

Analysis: Change working level N * (1 + 0.01); non-working day N * (1-0.01); for in use to traverse computational thinking 365 days

code:

. 1  # DayDayUp365.py storage file name 
2 dayup, dayfactor = 1.0,0.01
 . 3  for I in Range (365 ):
 . 4      IF I. 7% in [. 6 , 0]:    
 . 5          dayup dayup * = (l- dayfactor)
 . 6      the else :
 . 7          dayup dayup * = (1+ dayfactor)
 . 8  Print ( " up 2 days 5 days down force: {}. 2F :. " .format (dayup))

operation result:

Up 2 days 5 days down force: 4.63

Example 4:

According to the value of Example 3, to achieve the effect one year after the effort of 1% of the same day, weekdays should strive to what extent?

Analysis: The effort of 1% a day, a year after efforts to value: 37.78; solved by defining a function dayup

code:

. 1  DEF dayup (DF):
 2      dayup = 1.0
 . 3      for I in Range (365 ):
 . 4          IF I. 7% in [. 6 , 0]:    
 . 5              dayup dayup * = (1-0.01 )
 . 6          the else :
 . 7              dayup * = dayup (1+ DF)
 . 8      return dayup
 . 9 dayfactor 0.01 =
 10  the while (dayup (dayfactor) <37.78 ):
 . 11      dayfactor from 0.001 + =
 12 is  Print ( " parameter daily effort is: {} 3F :. ".format(dayfactor))

operation result:

Parameters effort every day: 0.019

learn by analogy:

Question changes:

(1) 1% increase in the level of effort working day, rest day level does not drop it?

(2) working days to rest one day, the ability to change the value?

(3) increased by 1% to the value of work, rest day down 0.1 percent?

And so these issues, readers can try it yourself in the following change to these questions

 

Examples include 1. Although only 8-12 lines of code, but contains a lot of syntax elements

2. Analyzing conditional loop while, the number of cycles for, branch if else, function def dayup (df)

3. To be able to clearly understand the code language python quick start

 

 

 

 

style

Guess you like

Origin www.cnblogs.com/cyt99/p/11811186.html