From 1fedd78204711b3ce8bbf9a7b76c5e16c67656bf Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Tue, 1 Nov 2022 19:51:39 +0530 Subject: [PATCH 01/20] Create guess_the_number_search.py --- other/guess_the_number_search.py | 150 +++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 other/guess_the_number_search.py diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py new file mode 100644 index 000000000000..44f141fa1409 --- /dev/null +++ b/other/guess_the_number_search.py @@ -0,0 +1,150 @@ +""" +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 + +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 +then: + num = int((lower+higher)/2) + for above statement the function already declared as the get_avg(a,b) + + [1] + 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 + answer(250) : low + + [3] + get_avg(250,500) : 375 + answer(375) : high + + [4] + get_avg(375,250) : 312 + answer(312) : low + + [5] + get_avg(312,375) : 343 + answer(343) : low + + [6] + get_avg(343,375) : 359 + answer(359) : high + + [7] + get_avg(343,359) : 351 + answer(351) : low + + [8] + get_avg(351,359) : 355 + answer(355) : same + +The number is found : 355 + +>>> guess_the_number(10, 1000, 17) +started... +guess the number : 17 +details : [505, 257, 133, 71, 40, 25, 17] + +""" + + +def temp_input_value(min_val: int = 10, max_val: int = 1000, option: int = True) -> int: + """ + Temporary input values for tests + + >>> temp_input_value(option=True) + 10 + + >>> temp_input_value(option=False) + 1000 + """ + if option is True: + return min_val + return max_val + + +def get_avg(a: int, b: int) -> int: + """ + Return the mid-number(whole) of two integers a and b + >>> get_avg(10,15) + 12 + >>> get_avg(20,300) + 160 + >>> get_avg("a",300) + Traceback (most recent call last): + ... + TypeError: can only concatenate str (not "int") to str + """ + return int((a + b) / 2) + + +def guess_the_number(lower: int, higher: int, to_guess: int) -> None: + """ + The `guess_the_number` function that guess the number by some operations + and using inner functions + + >>> guess_the_number(10, 1000, 17) + started... + guess the number : 17 + details : [505, 257, 133, 71, 40, 25, 17] + + >>> guess_the_number(10, 1000, "a") + Traceback (most recent call last): + ... + TypeError: '>' not supported between instances of 'int' and 'str' + """ + def answer(number: int) -> str: + """ + Returns value by comparing with entered `to_guess` number + """ + if number > to_guess: + return "high" + elif number < to_guess: + return "low" + else: + return "same" + + print("started...") + + last_lowest = lower + last_highest = higher + + last_numbers = [] + + while True: + number = get_avg(last_lowest, last_highest) + last_numbers.append(number) + + if answer(number) == "low": + last_lowest = number + elif answer(number) == "high": + last_highest = number + else: + break + + print(f"guess the number : {last_numbers[-1]}") + print(f"details : {str(last_numbers)}") + + +def main() -> None: + """ + starting point or function of script + """ + lower = int(input("Enter lower value : ").strip()) + higher = int(input("Enter high value : ").strip()) + guess = int(input("Enter value to guess : ").strip()) + guess_the_number(lower, higher, guess) + + +if __name__ == "__main__": + main() From aa3b2dae7850cec6e816ede64d59159db2e4afe8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Nov 2022 14:23:53 +0000 Subject: [PATCH 02/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 1 + 1 file changed, 1 insertion(+) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 44f141fa1409..e0a9cee95cbc 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -103,6 +103,7 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ... TypeError: '>' not supported between instances of 'int' and 'str' """ + def answer(number: int) -> str: """ Returns value by comparing with entered `to_guess` number From df9f802b559eabd7edd97a0658eb54fa1d1f42f2 Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Tue, 1 Nov 2022 20:01:01 +0530 Subject: [PATCH 03/20] Update guess_the_number_search.py --- other/guess_the_number_search.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index e0a9cee95cbc..f9d64c17580d 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -73,19 +73,19 @@ def temp_input_value(min_val: int = 10, max_val: int = 1000, option: int = True) return max_val -def get_avg(a: int, b: int) -> int: +def get_avg(number_1: int, number_2: int) -> int: """ Return the mid-number(whole) of two integers a and b >>> get_avg(10,15) 12 >>> get_avg(20,300) 160 - >>> get_avg("a",300) + >>> get_avg("abcd",300) Traceback (most recent call last): ... TypeError: can only concatenate str (not "int") to str """ - return int((a + b) / 2) + return int((number_1 + number_2) / 2) def guess_the_number(lower: int, higher: int, to_guess: int) -> None: @@ -103,7 +103,6 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ... TypeError: '>' not supported between instances of 'int' and 'str' """ - def answer(number: int) -> str: """ Returns value by comparing with entered `to_guess` number From 7d3956e8b0ae280c2dff8eb6142f1674e5d999bc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Nov 2022 14:33:35 +0000 Subject: [PATCH 04/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 1 + 1 file changed, 1 insertion(+) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index f9d64c17580d..32902fd37da8 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -103,6 +103,7 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ... TypeError: '>' not supported between instances of 'int' and 'str' """ + def answer(number: int) -> str: """ Returns value by comparing with entered `to_guess` number From 55527cb6a1c5bd4046860e3b29057f032488f2eb Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:22 +0530 Subject: [PATCH 05/20] Update other/guess_the_number_search.py Co-authored-by: Christian Clauss --- other/guess_the_number_search.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 32902fd37da8..846a661a28be 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -68,9 +68,7 @@ def temp_input_value(min_val: int = 10, max_val: int = 1000, option: int = True) >>> temp_input_value(option=False) 1000 """ - if option is True: - return min_val - return max_val + return min_val if option else max_val def get_avg(number_1: int, number_2: int) -> int: From e20e616f566eb625034dc8d71a2ea3e9001be990 Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:44 +0530 Subject: [PATCH 06/20] Update other/guess_the_number_search.py Co-authored-by: Christian Clauss --- other/guess_the_number_search.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 846a661a28be..6a95b4f53c1e 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -74,11 +74,11 @@ def temp_input_value(min_val: int = 10, max_val: int = 1000, option: int = True) def get_avg(number_1: int, number_2: int) -> int: """ Return the mid-number(whole) of two integers a and b - >>> get_avg(10,15) + >>> get_avg(10, 15) 12 - >>> get_avg(20,300) + >>> get_avg(20, 300) 160 - >>> get_avg("abcd",300) + >>> get_avg("abcd", 300) Traceback (most recent call last): ... TypeError: can only concatenate str (not "int") to str From aa5c12b1f9f5fe6974654a6e214158bdc1fd4ed0 Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:37:20 +0530 Subject: [PATCH 07/20] Update other/guess_the_number_search.py changed wrong mentioned datatype to correct Co-authored-by: Christian Clauss --- other/guess_the_number_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 6a95b4f53c1e..f9ed6cb87671 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -58,7 +58,7 @@ """ -def temp_input_value(min_val: int = 10, max_val: int = 1000, option: int = True) -> int: +def temp_input_value(min_val: int = 10, max_val: int = 1000, option: bool = True) -> int: """ Temporary input values for tests From 30fe32596b1347a7367dd9434cdc6e12bd6aef15 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 07:09:07 +0000 Subject: [PATCH 08/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index f9ed6cb87671..5c4e3686a700 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -58,7 +58,9 @@ """ -def temp_input_value(min_val: int = 10, max_val: int = 1000, option: bool = True) -> int: +def temp_input_value( + min_val: int = 10, max_val: int = 1000, option: bool = True +) -> int: """ Temporary input values for tests From 7569539af4200881974011130534cf477f82247e Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:02:37 +0530 Subject: [PATCH 09/20] added tests and added type checking statements --- other/guess_the_number_search.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 5c4e3686a700..095e0b2942c9 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -69,21 +69,53 @@ def temp_input_value( >>> temp_input_value(option=False) 1000 + + >>> temp_input_value(min_val=100, option=True) + 100 + + >>> temp_input_value(min_val=100, max_val=50) + Traceback (most recent call last): + ... + ValueError: Invalid value for min_val or max_val (min_value < max_value) + + >>> temp_input_value("ten","fifty",1) + Traceback (most recent call last): + ... + AssertionError: Invalid type of value(s) specified to function! + + >>> temp_input_value(min_val=-100, max_val=500) + -100 + + >>> temp_input_value(min_val=-5100, max_val=-100) + -5100 """ + assert type(min_val) == int and type(max_val) == int and \ + type(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 def get_avg(number_1: int, number_2: int) -> int: """ Return the mid-number(whole) of two integers a and b + >>> get_avg(10, 15) 12 + >>> get_avg(20, 300) 160 + >>> get_avg("abcd", 300) Traceback (most recent call last): ... TypeError: can only concatenate str (not "int") to str + + >>> get_avg(10.5,50.25) + 30 """ return int((number_1 + number_2) / 2) From 3795571e2bcd447b33d4b8c01ca61ba78c07d110 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 07:34:24 +0000 Subject: [PATCH 10/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 095e0b2942c9..8d4f9bec6834 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -89,13 +89,11 @@ def temp_input_value( >>> temp_input_value(min_val=-5100, max_val=-100) -5100 """ - assert type(min_val) == int and type(max_val) == int and \ - type(option) == bool, \ - "Invalid type of value(s) specified to function!" + assert ( + type(min_val) == int and type(max_val) == int and type(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)" - ) + raise ValueError("Invalid value for min_val or max_val (min_value < max_value)") return min_val if option else max_val From 9732e280cef3fe0adae96e976377be5935ffa52c Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:27:27 +0530 Subject: [PATCH 11/20] added tests and type checks for `guess_the_number` --- other/guess_the_number_search.py | 39 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 8d4f9bec6834..7635c38ae468 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -89,11 +89,13 @@ def temp_input_value( >>> temp_input_value(min_val=-5100, max_val=-100) -5100 """ - assert ( - type(min_val) == int and type(max_val) == int and type(option) == bool - ), "Invalid type of value(s) specified to function!" + assert type(min_val) == int and type(max_val) == int and \ + type(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)") + raise ValueError( + "Invalid value for min_val or max_val (min_value < max_value)" + ) return min_val if option else max_val @@ -128,11 +130,38 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: guess the number : 17 details : [505, 257, 133, 71, 40, 25, 17] + >>> guess_the_number(-10000, 10000, 7) + started... + guess the number : 7 + details : [0, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 6, 7] + >>> guess_the_number(10, 1000, "a") Traceback (most recent call last): ... - TypeError: '>' not supported between instances of 'int' and 'str' + AssertionError: argument values must be type of "int" + + >>> guess_the_number(10, 1000, 5) + Traceback (most recent call last): + ... + ValueError: guess value must be within the range of lower and higher value + + >>> guess_the_number(10000, 100, 5) + Traceback (most recent call last): + ... + ValueError: argument value for lower and higher must be(lower > higher) """ + assert type(lower) == int and type(higher) == int \ + and type(to_guess) == int, "argument values must be type of \"int\"" + + if lower > higher: + raise ValueError( + "argument value for lower and higher must be(lower > higher)" + ) + + if to_guess < lower or to_guess > higher: + raise ValueError( + "guess value must be within the range of lower and higher value" + ) def answer(number: int) -> str: """ From 318a2f846d6a676d070c722c952a6aeb76c4c301 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 07:58:55 +0000 Subject: [PATCH 12/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 7635c38ae468..ba248fd17dd1 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -89,13 +89,11 @@ def temp_input_value( >>> temp_input_value(min_val=-5100, max_val=-100) -5100 """ - assert type(min_val) == int and type(max_val) == int and \ - type(option) == bool, \ - "Invalid type of value(s) specified to function!" + assert ( + type(min_val) == int and type(max_val) == int and type(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)" - ) + raise ValueError("Invalid value for min_val or max_val (min_value < max_value)") return min_val if option else max_val @@ -150,13 +148,12 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ... ValueError: argument value for lower and higher must be(lower > higher) """ - assert type(lower) == int and type(higher) == int \ - and type(to_guess) == int, "argument values must be type of \"int\"" + assert ( + type(lower) == int and type(higher) == int and type(to_guess) == int + ), 'argument values must be type of "int"' if lower > higher: - raise ValueError( - "argument value for lower and higher must be(lower > higher)" - ) + raise ValueError("argument value for lower and higher must be(lower > higher)") if to_guess < lower or to_guess > higher: raise ValueError( From b98d8943a1b23b7982f0f152fd309e6e7246927b Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 18:17:12 +0530 Subject: [PATCH 13/20] fixed the issues - changed type checking technique - updated guess value checking --- other/guess_the_number_search.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index ba248fd17dd1..6cb5f6a16de1 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -89,11 +89,13 @@ def temp_input_value( >>> temp_input_value(min_val=-5100, max_val=-100) -5100 """ - assert ( - type(min_val) == int and type(max_val) == int and type(option) == bool - ), "Invalid type of value(s) specified to function!" + assert isinstance(min_val, int) 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)") + raise ValueError( + "Invalid value for min_val or max_val (min_value < max_value)" + ) return min_val if option else max_val @@ -148,14 +150,15 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ... ValueError: argument value for lower and higher must be(lower > higher) """ - assert ( - type(lower) == int and type(higher) == int and type(to_guess) == int - ), 'argument values must be type of "int"' + assert isinstance(lower, int) and isinstance(higher, int) \ + and isinstance(to_guess, int), "argument values must be type of \"int\"" if lower > higher: - raise ValueError("argument value for lower and higher must be(lower > higher)") + raise ValueError( + "argument value for lower and higher must be(lower > higher)" + ) - if to_guess < lower or to_guess > higher: + if not lower < to_guess < higher: raise ValueError( "guess value must be within the range of lower and higher value" ) From e007d4558631f0545b606947554d5144898e07d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:50:04 +0000 Subject: [PATCH 14/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 6cb5f6a16de1..868b7911a9dc 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -89,13 +89,13 @@ def temp_input_value( >>> temp_input_value(min_val=-5100, max_val=-100) -5100 """ - assert isinstance(min_val, int) and isinstance(max_val, int) and \ - isinstance(option, bool), \ - "Invalid type of value(s) specified to function!" + assert ( + isinstance(min_val, int) + 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)" - ) + raise ValueError("Invalid value for min_val or max_val (min_value < max_value)") return min_val if option else max_val @@ -150,13 +150,12 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ... ValueError: argument value for lower and higher must be(lower > higher) """ - assert isinstance(lower, int) and isinstance(higher, int) \ - and isinstance(to_guess, int), "argument values must be type of \"int\"" + assert ( + isinstance(lower, int) and isinstance(higher, int) and isinstance(to_guess, int) + ), 'argument values must be type of "int"' if lower > higher: - raise ValueError( - "argument value for lower and higher must be(lower > higher)" - ) + raise ValueError("argument value for lower and higher must be(lower > higher)") if not lower < to_guess < higher: raise ValueError( From 44497b6248c1397ac6979b4a8f818e09d9f8182e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 2 Nov 2022 15:21:51 +0100 Subject: [PATCH 15/20] Update guess_the_number_search.py --- other/guess_the_number_search.py | 35 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 868b7911a9dc..1ce746095ce0 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -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 @@ -54,7 +54,6 @@ started... guess the number : 17 details : [505, 257, 133, 71, 40, 25, 17] - """ From 29e8cd03c012c3e26ff1add18e58ed223d71c0c5 Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 20:57:11 +0530 Subject: [PATCH 16/20] updated after running black --- other/guess_the_number_search.py | 36 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 1ce746095ce0..df5c9a2e43f0 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -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 @@ -54,6 +54,7 @@ started... guess the number : 17 details : [505, 257, 133, 71, 40, 25, 17] + """ @@ -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 From ebc9800bfb5ca932608187fdc5f30d5461592509 Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Wed, 2 Nov 2022 21:43:29 +0530 Subject: [PATCH 17/20] Update guess_the_number_search.py --- other/guess_the_number_search.py | 53 +++----------------------------- 1 file changed, 5 insertions(+), 48 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index df5c9a2e43f0..c332e75e7c86 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -1,54 +1,9 @@ """ -get the random number guessed by the computer by passing the lower,higher -and the number to guess +guess the number using lower,higher and the value to find or 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 - -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 +solution works by dividing lower and higher of number guessed 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) - - [1] - 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 - answer(250) : low - - [3] - get_avg(250,500) : 375 - answer(375) : high - - [4] - get_avg(375,250) : 312 - answer(312) : low - - [5] - get_avg(312,375) : 343 - answer(343) : low - - [6] - get_avg(343,375) : 359 - answer(359) : high - - [7] - get_avg(343,359) : 351 - answer(351) : low - - [8] - get_avg(351,359) : 355 - answer(355) : same - -The number is found : 355 >>> guess_the_number(10, 1000, 17) started... @@ -96,7 +51,9 @@ def temp_input_value( ), "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)") + raise ValueError( + "Invalid value for min_val or max_val (min_value < max_value)" + ) return min_val if option else max_val From 9e411a172328440637ed2e0b39de7ceff6dd8cd9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:16:21 +0000 Subject: [PATCH 18/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index c332e75e7c86..0439223f2ec9 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -51,9 +51,7 @@ def temp_input_value( ), "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)" - ) + raise ValueError("Invalid value for min_val or max_val (min_value < max_value)") return min_val if option else max_val From 907d056aadf4743989ecbdf9a289e3c8e318a7ff Mon Sep 17 00:00:00 2001 From: Harkishan Khuva <78949167+hakiKhuva@users.noreply.github.com> Date: Sun, 6 Nov 2022 00:03:16 +0530 Subject: [PATCH 19/20] Update guess_the_number_search.py --- other/guess_the_number_search.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 0439223f2ec9..93e3f3f8975c 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -14,7 +14,9 @@ def temp_input_value( - min_val: int = 10, max_val: int = 1000, option: bool = True + min_val: int = 10, + max_val: int = 1000, + option: bool = True ) -> int: """ Temporary input values for tests @@ -107,7 +109,9 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ValueError: argument value for lower and higher must be(lower > higher) """ assert ( - isinstance(lower, int) and isinstance(higher, int) and isinstance(to_guess, int) + isinstance(lower, int) + and isinstance(higher, int) + and isinstance(to_guess, int) ), 'argument values must be type of "int"' if lower > higher: From 23fc205a6a7b5d890d4bb2872bb5202351f7ff9d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Nov 2022 18:35:00 +0000 Subject: [PATCH 20/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/guess_the_number_search.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/other/guess_the_number_search.py b/other/guess_the_number_search.py index 93e3f3f8975c..0439223f2ec9 100644 --- a/other/guess_the_number_search.py +++ b/other/guess_the_number_search.py @@ -14,9 +14,7 @@ def temp_input_value( - min_val: int = 10, - max_val: int = 1000, - option: bool = True + min_val: int = 10, max_val: int = 1000, option: bool = True ) -> int: """ Temporary input values for tests @@ -109,9 +107,7 @@ def guess_the_number(lower: int, higher: int, to_guess: int) -> None: ValueError: argument value for lower and higher must be(lower > higher) """ assert ( - isinstance(lower, int) - and isinstance(higher, int) - and isinstance(to_guess, int) + isinstance(lower, int) and isinstance(higher, int) and isinstance(to_guess, int) ), 'argument values must be type of "int"' if lower > higher: