File tree 1 file changed +20
-9
lines changed
1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change 1
1
import random
2
+ def cow_find (it1 ,it2 ):
3
+ c = 0
4
+ for x in it1 :
5
+ for y in range (len (it2 )):
6
+ if x == it2 [y ] and it2 [y ] != it1 [y ]:
7
+ c += 1
8
+ return c
9
+ def bull_find (it1 ,it2 ):
10
+ bulls = 0
11
+ c = list (zip (it1 ,it2 ))
12
+ for x ,y in c :
13
+ if x == y :
14
+ bulls += 1
15
+ return bulls
2
16
ln = int (input ("Enter secret number's length: " ))
3
17
attempts = int (input ("Enter attempts: " ))
4
18
rep = input ("Do you want to have same digits in the secret number?(y/n): " )
10
24
while len (str (num )) != len (set (str (num ))):
11
25
num = random .randint (n1 ,n2 )
12
26
print ("The number is " + str (len (str (num ))) + " digits long." )
27
+ num = 1231
13
28
guess = ""
14
29
nm = str (num )
15
30
pl = True
27
42
guess = int (input ("Enter number: " ))
28
43
if guess == - 1 :
29
44
print (num )
45
+ attempts += 1
46
+ continue
30
47
gs = str (guess )
31
- c = list (zip (nm ,gs ))
32
- for x ,y in c :
33
- if x == y :
34
- bulls += 1
35
- for z in gs :
36
- times = nm .count (z )
37
- cows += times
38
- cows -= bulls
48
+ bulls += bull_find (gs ,nm )
49
+ cows += cow_find (gs ,nm )
39
50
print ("Bulls: " + str (bulls ))
40
51
print ("Cows: " + str (cows ))
41
52
attempts -= 1
48
59
player = "Player 2"
49
60
print ("The number was {}. {} won!!" .format (num ,player ))
50
61
print ("You won in {} attempts" .format (att - attempts ))
51
- if att - attempts <= 4 :
62
+ if att - attempts <= att / 2 :
52
63
print ("Wow that luck/cheat brah!!!" )
53
64
input ("Press any key to exit..." )
You can’t perform that action at this time.
0 commit comments