forked from kying18/beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (28 loc) · 987 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import random
def guess(x):
random_number = random.randint(1, x)
guess = 0
while guess != random_number:
guess = int(input(f'Guess a number between 1 and {x}: '))
print(guess)
if guess < random_number:
print('Sorry, guess again. Too low.')
elif guess > random_number:
print('Sorry, guess again. Too high.')
print(f'Yay, congrats. You ahve guessed the number {random_number} correct!')
def computer_guess(x):
low = 1
high = x
feedback = ''
while feedback != 'c':
if low != high:
guess = random.randint(low, high)
else:
guess = low #could also be high
feedback = input(f'Is {guess} too high (H), too low (L), or correct (C)? ').lower()
if feedback == 'h':
high = guess - 1
elif feedback == 'l':
low = guess + 1
print(f'Yay! The computer guessed your number, {guess}, correctly!')
computer_guess(1000)