-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise_18.py
36 lines (29 loc) · 852 Bytes
/
Exercise_18.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
34
35
36
import random
def cows_bulls(number, g_number):
cow_bul = [0, 0]
for i in range(len(number)):
if number[i] == g_number[i]:
cow_bul[0] += 1
else:
cow_bul[1] += 1
print("Cows ", cow_bul, " Bulls")
return cow_bul
def main():
num = str(random.randint(0, 9999))
print("Welcome in cows&bulls game!"
"Please type your guess"
"In order to stop a game type exit")
guess_counter = 0
while True:
guess_counter += 1
user_input = input()
if user_input.lower() == "exit":
break
else:
result = cows_bulls(user_input, num)
if result[0] == 4:
print("You guessed the number")
print("You need only ", guess_counter, " guesses")
break
if __name__ == "__main__":
main()