python programming language basic exercise every day upward force (math.pow)

Example 1:

,, 365 days a year to the first day of base capacity is 1.0, when the ability to learn values ​​the previous day increased by 1%, compared to the ability to value the day before yesterday to a 1% reduction efforts and letting every single day when there is no learning, capacity a year down the value of the difference between how much?

Resolution:

If all learn every day, then, is to calculate the 365 th 1.01, why is it 365? Because this capacity value of 1 is the first day to have, then you need to learn the first day of 1.01 multiplied, as the first day of harvest, the first day of 1.0 * (1 + 1%), the next day is 1.0 * (1 + 1%) ** 2 ......... day 365 1.0 * (1 + 1%) ** 364. x ** y means in python x to the power of y. Similarly available laissez-faire, then every day is 365 computing power of 0.99. Use math library math.pow function can be very easy to write.

Code:

import math // reference math library
dayup Math.pow = ((. 1 + 0.01), 365)
daydown Math.pow = ((1-0.01), 365)
C = dayup-daydown
Print (round (dayup,. 3)) / / output capacity hard every day year-end value of the
print (round (daydown, 3) ) output faire value every day year-end capability
capacity value print (round (c, 3) ) of the difference output

Screenshot operating results

 

Example 2

365 days a year ,, initial value of 1.0, a day's work to improve the level of N, does not work when the level does not drop, the work week for four consecutive days, try programming operation result? When N = 0.01

Resolution:

Year 365/7 = 52 weeks I still day, four days a week, 208 days of the year to work. Assuming that the first day of the year Monday, the last day of this year's extra day is Monday.

Let us assume that working hours

Option One, Week 1234, the time of the year is 209 days of work.

Code:

import math
x=1
N=0.01

for i in range(1,366):
  if i%7 in[1,2,3,4]:
    x=x*(1+N)
  else:
    x=x
print(round(x,3))

operation result

8.001

Option Two, Week 2345, the time of the year of 208 working days,

Code:

import math
x=1
N=0.01

for i in range(1,366):
if i%7 in[5,2,3,4]:
x=x*(1+N)
else:
x=x
print(round(x,3))

operation result

7.922

Option Three, Week 3456, the time of the year is 208 days of work.

Code:

import math
x=1
N=0.01

for i in range(1,366):
  if i%7 in[6,5,3,4]:
    x=x*(1+N)
  else:
    x=x
print(round(x,3))

operation result

Option IV, Week 4567, the time of the year is 208 days of work.

Code:

import math
x=1
N=0.01

for i in range(1,366):
  if i%7 in[4,5,6,0]:
    x=x*(1+N)
  else:
    x=x
print(round(x,3))

operation result

 7.922

Program V. Week 5671, the time of the year is 209 days of work.

Code:

import math
x=1
N=0.01

for i in range(1,366):
  if i%7 in[5,6,0,1]:
    x=x*(1+N)
  else:
    x=x
print(round(x,3))

operation result

8.001

Program Six, Week 6712, the time of the year is 209 days of work.

Code:

import math
x=1
N=0.01

for i in range(1,366):
  if i%7 in[1,2,0,6]:
    x=x*(1+N)
  else:
    x=x
print(round(x,3))

operation result

8.001

Scheme VII Week 7123, the time of the year is 209 days of work.

Code:

import math
x=1
N=0.01

for i in range(1,366):
  if i%7 in[1,2,3,4]:
    x=x*(1+N)
  else:
    x=x
print(round(x,3))

operation result

8.001

 Summary: One is to include one more day Monday, 209 days. One is not included for 208 days.

Guess you like

Origin www.cnblogs.com/sunblingbling/p/11520683.html