forked from Krushna-Prasad-Sahoo/Sorting-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullcowgame.py
60 lines (48 loc) · 1.93 KB
/
bullcowgame.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import random as rand
import emoji as emo
emo_cow = emo.emojize(emo.demojize('🐄'))
emo_bull = emo.emojize(emo.demojize('🐂'))
print('\n\033[1m' + ' --: Welcome to Cows (', emo_cow, ') and Bulls (', emo_bull, ') game :--' + '\033[0m')
rand_num = rand.randrange(1000, 9999, 1)
rand_num_list = list(str(rand_num).replace("", ""))
trial = 0
error_dig = 0
error_let = 0
while True:
user_num = input('Guess the 4 digit number : ')
user_num_list = list(str(user_num).replace("", ""))
def if_contain_letter(x):
for ele in x:
if ele.isalpha():
con = True
else:
con = False
return con
if len(user_num_list) != 4:
print(' DIGIT no. Error : \n Your entered number does not contain 4 digits')
error_dig += 1
if error_dig > 3:
print('*) WARNING !! What are you doing ? Too much errors ! Be careful !')
if if_contain_letter(user_num_list):
print('DIGIT type Error :\n inputted number contains letter ')
error_let += 1
if not if_contain_letter(user_num_list):
if len(user_num_list) == 4:
a = []
b = []
for i in range(len(user_num_list)):
if rand_num_list[i] == user_num_list[i]:
a.append(user_num_list[i])
if rand_num_list[i] != user_num_list[i]:
if user_num_list[i] in rand_num_list:
b.append(user_num_list[i])
num_of_cow = len(a)
num_of_bull = len(b)
print(num_of_cow, ' cow (', emo_cow, ')')
print(num_of_bull, ' bull (', emo_bull, ')')
trial += 1
if str(user_num) == str(rand_num):
print('\n\033[1m' + '### Congratulations! , Well played ###' + '\033[0m')
print('Trials = ', trial)
print('Errors = ', error_dig + error_let)
break