-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython problem 6.py
More file actions
47 lines (34 loc) · 1.04 KB
/
python problem 6.py
File metadata and controls
47 lines (34 loc) · 1.04 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
39
40
41
42
43
44
45
46
47
# Guess The Number
import random
a = int(input("Enter the value of a:\n"))
b = int(input("Enter the value of b:\n"))
# generating random number
random_int = random.randint(a, b)
trials = 1
for i in range(2):
print('\n', end='')
if i == 0:
print("Player 1")
else:
print("Player 2")
while True:
user_guess = int(input(f"Please guess the number between {a} and {b}:\n"))
if user_guess > random_int:
print(f"Wrong, guess a smaller number again.")
trials += 1
elif user_guess < random_int:
print(f'Wrong, guess a smaller number again.')
trials += 1
elif user_guess == random_int:
print(f"Correct, you took {trials} to guess the number.")
if i == 0:
trial1 = trials
else:
trial2 = trials
trials = 1
break
print('\n', end='')
if trial1 < trial2:
print(f"Player 1 wins!")
else:
print(f"Player 2 wins!")