Advertisement
SimeonTs

SUPyF Lists - Extra 05. * Note Statistics

Jun 21st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.14 KB | None | 0 0
  1. """
  2. Lists
  3. Check your answer: https://judge.softuni.bg/Contests/Practice/Index/425#4
  4.  
  5. 05. * Note Statistics
  6.  
  7. Problem:
  8. In music, certain frequencies correspond to certain musical notes (example: A -> 440hz, C# -> 554.37hz).
  9. You will be given frequencies as real numbers on the first line of the input (space-separated).
  10. Your task is to convert the numbers to their musical note representation,
  11. then separate them into naturals (C, B, F and etc.) and sharp notes (C#, F#, A#, etc.).
  12. After that, print both lists in the console in the format described in the examples.
  13. After you print them, sum each list’s frequencies and print it on the console, rounded to the second decimal place.
  14.  
  15. Constraints
  16. The frequencies in the input will be constrained to this chart:
  17. Note    Frequency
  18. C       261.63hz
  19. C#      277.18hz
  20. D       293.66hz
  21. D#      311.13hz
  22. E       329.63hz
  23. F       349.23hz
  24. F#      369.99hz
  25. G       392.00hz
  26. G#      415.30hz
  27. A       440.00hz
  28. A#      466.16hz
  29. B       493.88hz
  30. """
  31.  
  32. all_frequencies = [float(item) for item in input().split(" ")]
  33.  
  34. notes = []
  35. naturals = []
  36. sharps = []
  37. naturals_sum = 0
  38. sharps_sum = 0
  39.  
  40. for frequency in all_frequencies:
  41.  
  42.     if frequency == 261.63:
  43.         # C - 261.63hz
  44.         notes += ["C"]
  45.         naturals += ["C"]
  46.         naturals_sum += 261.63
  47.     elif frequency == 277.18:
  48.         # C# - 277.18hz
  49.         notes += ["C#"]
  50.         sharps += ["C#"]
  51.         sharps_sum += 277.18
  52.     elif frequency == 293.66:
  53.         # D - 293.66hz
  54.         notes += ["D"]
  55.         naturals += ["D"]
  56.         naturals_sum += 293.66
  57.     elif frequency == 311.13:
  58.         # D# - 311.13hz
  59.         notes += ["D#"]
  60.         sharps += ["D#"]
  61.         sharps_sum += 311.13
  62.     elif frequency == 329.63:
  63.         # E - 329.63hz
  64.         notes += ["E"]
  65.         naturals += ["E"]
  66.         naturals_sum += 329.63
  67.     elif frequency == 349.23:
  68.         # F - 349.23hz
  69.         notes += ["F"]
  70.         naturals += ["F"]
  71.         naturals_sum += 349.23
  72.     elif frequency == 369.99:
  73.         # F# - 369.99hz
  74.         notes += ["F#"]
  75.         sharps += ["F#"]
  76.         sharps_sum += 369.99
  77.     elif frequency == 392.00:
  78.         # G - 392.00hz
  79.         notes += ["G"]
  80.         naturals += ["G"]
  81.         naturals_sum += 392.00
  82.     elif frequency == 415.30:
  83.         # G# - 415.30hz
  84.         notes += ["G#"]
  85.         sharps += ["G#"]
  86.         sharps_sum += 415.30
  87.     elif frequency == 440.00:
  88.         # A - 440.00hz
  89.         notes += ["A"]
  90.         naturals += ["A"]
  91.         naturals_sum += 440.00
  92.     elif frequency == 466.16:
  93.         # A# - 466.16hz
  94.         notes += ["A#"]
  95.         sharps += ["A#"]
  96.         sharps_sum += 466.16
  97.     elif frequency == 493.88:
  98.         # B - 493.88hz
  99.         notes += ["B"]
  100.         naturals += ["B"]
  101.         naturals_sum += 493.88
  102.  
  103. print(f"Notes: ", end="")
  104. for note in notes:
  105.     print(note, end=" ")
  106. print()
  107.  
  108. print(f"Naturals: ", end="")
  109. print(", ".join(naturals))
  110.  
  111. print(f"Sharps: ", end="")
  112. print(", ".join(sharps))
  113.  
  114. print(f"Naturals sum: ", end="")
  115. print('{:.2f}'.format(naturals_sum).rstrip("0").rstrip("."))
  116.  
  117. print(f"Sharps sum: ", end="")
  118. print('{:.2f}'.format(sharps_sum).rstrip("0").rstrip("."))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement