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(-10000, 10000, 7) started... gu
(lower: int, higher: int, to_guess: int)
| 77 | |
| 78 | |
| 79 | def guess_the_number(lower: int, higher: int, to_guess: int) -> None: |
| 80 | """ |
| 81 | The `guess_the_number` function that guess the number by some operations |
| 82 | and using inner functions |
| 83 | |
| 84 | >>> guess_the_number(10, 1000, 17) |
| 85 | started... |
| 86 | guess the number : 17 |
| 87 | details : [505, 257, 133, 71, 40, 25, 17] |
| 88 | |
| 89 | >>> guess_the_number(-10000, 10000, 7) |
| 90 | started... |
| 91 | guess the number : 7 |
| 92 | details : [0, 5000, 2500, 1250, 625, 312, 156, 78, 39, 19, 9, 4, 6, 7] |
| 93 | |
| 94 | >>> guess_the_number(10, 1000, "a") |
| 95 | Traceback (most recent call last): |
| 96 | ... |
| 97 | AssertionError: argument values must be type of "int" |
| 98 | |
| 99 | >>> guess_the_number(10, 1000, 5) |
| 100 | Traceback (most recent call last): |
| 101 | ... |
| 102 | ValueError: guess value must be within the range of lower and higher value |
| 103 | |
| 104 | >>> guess_the_number(10000, 100, 5) |
| 105 | Traceback (most recent call last): |
| 106 | ... |
| 107 | ValueError: argument value for lower and higher must be(lower > higher) |
| 108 | """ |
| 109 | assert ( |
| 110 | isinstance(lower, int) and isinstance(higher, int) and isinstance(to_guess, int) |
| 111 | ), 'argument values must be type of "int"' |
| 112 | |
| 113 | if lower > higher: |
| 114 | raise ValueError("argument value for lower and higher must be(lower > higher)") |
| 115 | |
| 116 | if not lower < to_guess < higher: |
| 117 | raise ValueError( |
| 118 | "guess value must be within the range of lower and higher value" |
| 119 | ) |
| 120 | |
| 121 | def answer(number: int) -> str: |
| 122 | """ |
| 123 | Returns value by comparing with entered `to_guess` number |
| 124 | """ |
| 125 | if number > to_guess: |
| 126 | return "high" |
| 127 | elif number < to_guess: |
| 128 | return "low" |
| 129 | else: |
| 130 | return "same" |
| 131 | |
| 132 | print("started...") |
| 133 | |
| 134 | last_lowest = lower |
| 135 | last_highest = higher |
| 136 |