forked from shecoderfinally/Basic-Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
38 lines (32 loc) · 1.13 KB
/
code.py
File metadata and controls
38 lines (32 loc) · 1.13 KB
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
import random
def guess(x):
random_number = random.randint(1, x)
guessedno = 0
while guessedno != random_number:
guessedno = int(input(f"Enter a number between 1 and {x}: "))
if guessedno > random_number:
print("Guess again.Too high")
elif guessedno < random_number:
print("Guess again.Too low")
print(f"Congratulations!! You have guessed the random_number ={random_number} ")
def computer_guess(x):
low = 1
high = x
feedback = ''
while feedback != 'C':
if low != high:
# This will give problem if low==high
random_number = random.randint(low, high)
print(random_number)
else:
random_number = low
print("Menu:")
print("Too high(H)")
print("Too low(L)")
print("Correct(C)")
feedback = input("Your choice: ").upper()
if feedback == 'L':
low = random_number+1
elif feedback == 'H':
high = random_number-1
print(f"Congratulations!! You have guessed the random_number ={random_number} ")