├── README.md ├── image1.PNG ├── image2.PNG └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # Guess_Number 2 | - Computer guessed the number 3 | 4 | 5 | - User need to guess the number 6 | 7 | -------------------------------------------------------------------------------- /image1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akrish4/Guess_Number/bf4a0f7d914e7ebd7b0892a8630355833c5e91ae/image1.PNG -------------------------------------------------------------------------------- /image2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akrish4/Guess_Number/bf4a0f7d914e7ebd7b0892a8630355833c5e91ae/image2.PNG -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def guess(x): 4 | random_number = random.randint(1, x) 5 | guess = 0 6 | while guess != random_number: 7 | guess = int(input(f'Guess a number between 1 and {x}: ')) 8 | if guess < random_number: 9 | print('Sorry, guess again. Too low.') 10 | elif guess > random_number: 11 | print('Sorry, guess again. Too high.') 12 | 13 | print(f'Yay, congrats. You have guessed the number {random_number} correctly!!') 14 | 15 | def computer_guess(x): 16 | low = 1 17 | high = x 18 | feedback = '' 19 | while feedback != 'c': 20 | if low != high: 21 | guess = random.randint(low, high) 22 | else: 23 | guess = low # could also be high b/c low = high 24 | feedback = input(f'Is {guess} too high (H), too low (L), or correct (C)?? ').lower() 25 | if feedback == 'h': 26 | high = guess - 1 27 | elif feedback == 'l': 28 | low = guess + 1 29 | 30 | print(f'Yay! The computer guessed your number, {guess}, correctly!') 31 | 32 | 33 | guess(10) --------------------------------------------------------------------------------