Skip to content

Commit d0806b3

Browse files
committedNov 25, 2016
DEBUGGED
1 parent d9c36f7 commit d0806b3

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed
 

‎cows and bulls.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
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
216
ln = int(input("Enter secret number's length: "))
317
attempts = int(input("Enter attempts: "))
418
rep = input("Do you want to have same digits in the secret number?(y/n): ")
@@ -10,6 +24,7 @@
1024
while len(str(num)) != len(set(str(num))):
1125
num = random.randint(n1,n2)
1226
print("The number is " + str(len(str(num))) + " digits long.")
27+
num = 1231
1328
guess = ""
1429
nm = str(num)
1530
pl = True
@@ -27,15 +42,11 @@
2742
guess = int(input("Enter number: "))
2843
if guess == -1:
2944
print(num)
45+
attempts += 1
46+
continue
3047
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)
3950
print("Bulls: " + str(bulls))
4051
print("Cows: " + str(cows))
4152
attempts -= 1
@@ -48,6 +59,6 @@
4859
player = "Player 2"
4960
print("The number was {}. {} won!!".format(num,player))
5061
print("You won in {} attempts".format(att-attempts))
51-
if att - attempts <= 4:
62+
if att - attempts <= att/2:
5263
print("Wow that luck/cheat brah!!!")
5364
input("Press any key to exit...")

0 commit comments

Comments
 (0)
Please sign in to comment.