MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_112/sol1.py:55–84  ·  view source on GitHub ↗

Returns the least number for which the proportion of bouncy numbers is exactly 'percent' >>> solution(50) 538 >>> solution(90) 21780 >>> solution(80) 4770 >>> solution(105) Traceback (most recent call last): ... ValueError: solution()

(percent: float = 99)

Source from the content-addressed store, hash-verified

53
54
55def solution(percent: float = 99) -> int:
56 """
57 Returns the least number for which the proportion of bouncy numbers is
58 exactly 'percent'
59 >>> solution(50)
60 538
61 >>> solution(90)
62 21780
63 >>> solution(80)
64 4770
65 >>> solution(105)
66 Traceback (most recent call last):
67 ...
68 ValueError: solution() only accepts values from 0 to 100
69 >>> solution(100.011)
70 Traceback (most recent call last):
71 ...
72 ValueError: solution() only accepts values from 0 to 100
73 """
74 if not 0 < percent < 100:
75 raise ValueError("solution() only accepts values from 0 to 100")
76 bouncy_num = 0
77 num = 1
78
79 while True:
80 if check_bouncy(num):
81 bouncy_num += 1
82 if (bouncy_num / num) * 100 >= percent:
83 return num
84 num += 1
85
86
87if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

check_bouncyFunction · 0.85

Tested by

no test coverage detected