Skip to content

Create guess_the_number_search.py #7937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 17, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1fedd78
Create guess_the_number_search.py
hakiKhuva Nov 1, 2022
aa3b2da
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 1, 2022
df9f802
Update guess_the_number_search.py
hakiKhuva Nov 1, 2022
7d3956e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 1, 2022
55527cb
Update other/guess_the_number_search.py
hakiKhuva Nov 2, 2022
e20e616
Update other/guess_the_number_search.py
hakiKhuva Nov 2, 2022
aa5c12b
Update other/guess_the_number_search.py
hakiKhuva Nov 2, 2022
30fe325
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2022
7569539
added tests and added type checking statements
hakiKhuva Nov 2, 2022
3795571
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2022
9732e28
added tests and type checks for `guess_the_number`
hakiKhuva Nov 2, 2022
318a2f8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2022
b98d894
fixed the issues
hakiKhuva Nov 2, 2022
e007d45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2022
44497b6
Update guess_the_number_search.py
cclauss Nov 2, 2022
29e8cd0
updated after running black
hakiKhuva Nov 2, 2022
ebc9800
Update guess_the_number_search.py
hakiKhuva Nov 2, 2022
9e411a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2022
907d056
Update guess_the_number_search.py
hakiKhuva Nov 5, 2022
23fc205
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions other/guess_the_number_search.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
"""
Get the random number guessed by the computer by passing the lower, higher, and the
number to guess.
get the random number guessed by the computer by passing the lower,higher
and the number to guess

This solution works on divide and getting the half of number of previous and current,
this depends on the number is low or high
this solution works on divide and getting the half of number of previous and
current, this depends on the number is low or high

If the number is more than last lower and less than to the number to guess then the
number is assigned to it, and same but opposite for higher number.
if the number is more than last lower and less than to the number to guess then
the number is assigned to it, and same but opposite for higher number

Suppose lower is 0, higher is 1000 and the number to guess is 355
suppose lower is 0, higher is 1000 and the number to guess is 355
then:
num = int((lower + higher) // 2)
for above statement the function already declared as the get_avg(a, b)
num = int((lower+higher)/2)
for above statement the function already declared as the get_avg(a,b)

[1]
get_avg(0, 1000) : 500
get_avg(0,1000) : 500
answer(500) : high
Now this value is passed to the answer function and that returns the
passed number is lower than the guess number or higher than the guess
number and also for equality

[2]
get_avg(0, 500) : 250
get_avg(0,500) : 250
answer(250) : low

[3]
get_avg(250, 500) : 375
get_avg(250,500) : 375
answer(375) : high

[4]
get_avg(375, 250) : 312
get_avg(375,250) : 312
answer(312) : low

[5]
get_avg(312, 375) : 343
get_avg(312,375) : 343
answer(343) : low

[6]
get_avg(343, 375) : 359
get_avg(343,375) : 359
answer(359) : high

[7]
get_avg(343, 359) : 351
get_avg(343,359) : 351
answer(351) : low

[8]
get_avg(351, 359) : 355
get_avg(351,359) : 355
answer(355) : same

The number is found : 355
Expand All @@ -54,6 +54,7 @@
started...
guess the number : 17
details : [505, 257, 133, 71, 40, 25, 17]

"""


Expand Down Expand Up @@ -93,6 +94,7 @@ def temp_input_value(
and isinstance(max_val, int)
and isinstance(option, bool)
), "Invalid type of value(s) specified to function!"

if min_val > max_val:
raise ValueError("Invalid value for min_val or max_val (min_value < max_value)")
return min_val if option else max_val
Expand Down