Skip to content

Instantly share code, notes, and snippets.

@RVDaescu
Created July 16, 2017 17:32
Show Gist options
  • Save RVDaescu/1553c5f9ec00bcb8b1b6ae5278e7818b to your computer and use it in GitHub Desktop.
Save RVDaescu/1553c5f9ec00bcb8b1b6ae5278e7818b to your computer and use it in GitHub Desktop.
cows and bulls
import random
def cab():
a = int(random.randint(1000, 9999))
print a
status = False
while status is False:
i = input('Choose a 4 digit number: ')
if i not in range(1000, 9999):
print 'Incorrect number; choose again!'
cab()
cows = 0
bulls = 0
for j in range(4):
if str(i)[j] == str(a)[j]:
cows += 1
elif str(i)[j] in str(a):
bulls += 1
if a == i:
print 'You guessed the number'
status = True
else:
print '%d cows; %d bulls' %(cows, bulls)
cab()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment