Monkey eats buns (Python)

Problem description
  Once upon a time, there was a monkey who was very good at eating steamed buns. It could eat countless steamed steamed buns. However, it eats different steamed buns at different speeds; meat buns eat x per second; leek buns eat y per second; no The stuffed buns eat z per second; now there are x1 meat buns, y1 leek buns, and z1 buns without stuffing. Q: How long will it take for the monkey to finish these buns? The result retains p decimal places.
Input format
  input 1 line, containing 7 integers, respectively representing the speed of eating different buns and the number of different buns and the number of bits reserved.
Output format
  output one line, including 1 real number, which means the time to eat all the buns.

Problem solving and ideas: This
problem is equivalent to a division problem. We only need to calculate the time spent eating each kind of buns and add them, and then determine the decimal to get the result.
Here we provide functional programming implementation and direct writing.
Functional:

def eat(x):  #one到four分别是一种包子用时和保留小数
    one = x[3]/x[0]
    two = x[4]/x[1]
    three = x[5]/x[2]
    four = x[6]
    tim = one + two + three
    print(round(tim,four))
x = [int(i) for i in input().split()]
eat(x)  

Write directly:

x = [int(i) for i in input().split()]
one = x[3]/x[0]
two = x[4]/x[1]
three = x[5]/x[2]
four = x[6]
tim = one + two + three
print(round(tim,four))

Guess you like

Origin blog.csdn.net/qq_45701131/article/details/106643577