dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
2.9 KiB
2.9 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6a19b1062d1b153d8ac76d71 | Challenge 323: Song Mood Finder | 29 | challenge-323 |
--description--
Given a genre string and a BPM number for a song, determine the mood using the following table:
| Mood | Genre | BPM Range |
|---|---|---|
"focus" |
"classical" |
60–109 |
"focus" |
"electronic" |
60–89 |
"happy" |
"pop" |
60–180 |
"happy" |
"classical" |
110–180 |
"happy" |
"rock" |
60–129 |
"happy" |
"electronic" |
90–134 |
"hype" |
"rock" |
130–180 |
"hype" |
"electronic" |
135–180 |
--hints--
get_mood("rock", 111) should return "happy".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("rock", 111), "happy")`)
}})
get_mood("electronic", 74) should return "focus".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("electronic", 74), "focus")`)
}})
get_mood("classical", 180) should return "happy".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("classical", 180), "happy")`)
}})
get_mood("rock", 155) should return "hype".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("rock", 155), "hype")`)
}})
get_mood("electronic", 90) should return "happy".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("electronic", 90), "happy")`)
}})
get_mood("classical", 67) should return "focus".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("classical", 67), "focus")`)
}})
get_mood("pop", 100) should return "happy".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("pop", 100), "happy")`)
}})
get_mood("electronic", 135) should return "hype".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_mood("electronic", 135), "hype")`)
}})
--seed--
--seed-contents--
def get_mood(genre, bpm):
return genre
--solutions--
def get_mood(genre, bpm):
table = [
{"mood": "focus", "genre": "classical", "min": 60, "max": 109},
{"mood": "focus", "genre": "electronic", "min": 60, "max": 89},
{"mood": "happy", "genre": "pop", "min": 60, "max": 180},
{"mood": "happy", "genre": "classical", "min": 110, "max": 180},
{"mood": "happy", "genre": "rock", "min": 60, "max": 129},
{"mood": "happy", "genre": "electronic", "min": 90, "max": 134},
{"mood": "hype", "genre": "rock", "min": 130, "max": 180},
{"mood": "hype", "genre": "electronic", "min": 135, "max": 180},
]
return next(row["mood"] for row in table if row["genre"] == genre and row["min"] <= bpm <= row["max"])