Python please!

On a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * rn, where n is the distance (number of keys) from that key, and r is 2(1/12). Given an initial key frequency, output that frequency and the next 4 higher key frequencies.


Output each floating-point value with two digits after the decimal point, which can be achieved as follows:

print('{:.2f} {:.2f} {:.2f} {:.2f} {:.2f}'.format(your_value1, your_value2, your_value3, your_value4, your_value5))


Ex: If the input is: 440

(which is the A key near the middle of a piano keyboard), the output is: 440.00 466.16 493.88 523.25 554.37


Note: Use one statement to compute r = 2(1/12) using the pow function (remember to import the math module). Then use that r in subsequent statements that use the formula fn = f0 * rn with n being 1, 2, 3, and finally 4.


I inserted what I've already done and what error message I'm getting.

Respuesta :

We have that the output that frequency with the next 4 higher key frequencies  is mathematically given as

Output

  • 120,127,13,134.8,142,1,151.19

From the question we are told

  • On a piano, a key has a frequency, say f0.
  • Each higher key (black or white) has a frequency of f0 * rn, where n is the distance (number of keys) from that key, and r is 2(1/12).
  • Given an initial key frequency, output that frequency and the next 4 higher key frequencies.

Output each floating-point value with two digits after the decimal point, which can be achieved as follows:

Output and frequency

Generally the code will go as follows

# The key frequency

f0 = float(input())

r = math.pow(2, (1 / 12))

# The frequency, the next 4 higher key f's.

frequency1 = f0 * math.pow(r, 0)

frequency2 = f0 * math.pow(r, 1)

frequency3 = f0 * math.pow(r, 2)

frequency4 = f0 * math.pow(r, 3)

frequency5 = f0 * math.pow(r, 4)

# printing output

print('{:.2f} {:.2f} {:.2f} {:.2f} {:.2f}'.format(frequency1, frequency2, frequency3, frequency4, frequency5))

Therefore

Output

120,127,13,134.8,142,1,151.19

For more information on frequency visit

https://brainly.com/question/22568180

ACCESS MORE