Created
July 16, 2017 17:32
-
-
Save RVDaescu/1553c5f9ec00bcb8b1b6ae5278e7818b to your computer and use it in GitHub Desktop.
cows and bulls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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