Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/6a2037a68a0bc2aef0006006.md
T
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.6 KiB
Markdown

---
id: 6a2037a68a0bc2aef0006006
title: "Challenge 344: Golden Ratio"
challengeType: 29
dashedName: challenge-344
---
# --description--
Given two numbers, determine if their ratio approximates the golden ratio.
- Use a golden ratio of `1.618`
- Allow a tolerance of `0.01`
# --hints--
`is_golden_ratio(21, 34)` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(21, 34), True)`)
}})
```
`is_golden_ratio(15, 20)` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(15, 20), False)`)
}})
```
`is_golden_ratio(8, 13)` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(8, 13), True)`)
}})
```
`is_golden_ratio(10, 16)` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(10, 16), False)`)
}})
```
`is_golden_ratio(1618, 1000)` should return `True`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(1618, 1000), True)`)
}})
```
`is_golden_ratio(88, 55)` should return `False`.
```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(88, 55), False)`)
}})
```
# --seed--
## --seed-contents--
```py
def is_golden_ratio(a, b):
return a
```
# --solutions--
```py
def is_golden_ratio(a, b):
golden_ratio = 1.618
ratio = max(a, b) / min(a, b)
return abs(ratio - golden_ratio) <= 0.01
```