-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguess.pu
50 lines (33 loc) · 1.07 KB
/
guess.pu
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
34
35
36
37
38
39
40
2 guessing number (pc)
import random
try:
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}: '))
if guess < random_number:
print('Sorrr, guess again. Too low.')
elif guess > random_number:
print('Guess again. Too hight.')
print(f'Yay, congrats. you have guessed the number {random_number} correctly!!!')
x = int(input())
guess(x)
except:
print('INPUT INT MAN!')
def computer_guess(x):
low = 1
hight = x
feedback = ''
while feedback != 'c':
if low != hight:
guess = random.randint(low, hight)
else:
guess = low
feedback = input(f'Is {guess} too hight (H), too low (L), or correct (c): ')
if feedback == 'h':
hight = guess - 1
elif feedback == 'l':
low = guess + 1
print(f'Yay! The computer guessed your number, {guess} correctly!')
computer_guess(1000)