Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

89 lines
1.7 KiB
Markdown

---
id: 69cfca90e8a0a6d4d6871c50
title: "Challenge 266: Good Day"
challengeType: 29
dashedName: challenge-266
---
# --description--
Given a time string in `"HH:MM"` format (24-hour clock), return:
- `"Good morning"` for times `05:00` to `11:59`
- `"Good afternoon"` for times `12:00` to `17:59`
- `"Good evening"` for times `18:00` to `21:59`
- `"Good night"` for times `22:00` to `04:59`
# --hints--
`get_greeting("06:30")` should return `"Good morning"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_greeting("06:30"), "Good morning")`)
}})
```
`get_greeting("12:00")` should return `"Good afternoon"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_greeting("12:00"), "Good afternoon")`)
}})
```
`get_greeting("21:59")` should return `"Good evening"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_greeting("21:59"), "Good evening")`)
}})
```
`get_greeting("00:01")` should return `"Good night"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_greeting("00:01"), "Good night")`)
}})
```
`get_greeting("11:30")` should return `"Good morning"`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_greeting("11:30"), "Good morning")`)
}})
```
# --seed--
## --seed-contents--
```py
def get_greeting(s):
return s
```
# --solutions--
```py
def get_greeting(s):
hours, minutes = map(int, s.split(':'))
total = hours * 60 + minutes
if 300 <= total < 720:
return 'Good morning'
if 720 <= total < 1080:
return 'Good afternoon'
if 1080 <= total < 1320:
return 'Good evening'
return 'Good night'
```