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

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a2037a68a0bc2aef0006006 Challenge 344: Golden Ratio 29 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.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(21, 34), True)`)
}})

is_golden_ratio(15, 20) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(15, 20), False)`)
}})

is_golden_ratio(8, 13) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(8, 13), True)`)
}})

is_golden_ratio(10, 16) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(10, 16), False)`)
}})

is_golden_ratio(1618, 1000) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(1618, 1000), True)`)
}})

is_golden_ratio(88, 55) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_golden_ratio(88, 55), False)`)
}})

--seed--

--seed-contents--

def is_golden_ratio(a, b):

    return a

--solutions--

def is_golden_ratio(a, b):
    golden_ratio = 1.618
    ratio = max(a, b) / min(a, b)
    return abs(ratio - golden_ratio) <= 0.01