Created
June 7, 2017 20:32
-
-
Save Sam-Belliveau/3104594bd4bf15a922acadd08e77795f to your computer and use it in GitHub Desktop.
This file contains 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 | |
import re | |
digits = ['0','1','2','3','4','5','6','7','8','9'] | |
while True: | |
num1 = random.choice(digits) | |
while num1 == '0': | |
num1 = random.choice(digits) | |
num2 = random.choice(digits) | |
while (num2 == num1): | |
num2 = random.choice(digits) | |
num3 = random.choice(digits) | |
while (num3 == num1) or (num3 == num2): | |
num3 = random.choice(digits) | |
num4 = random.choice(digits) | |
while (num4 == num1) or (num4 == num2) or (num4 == num3): | |
num4 = random.choice(digits) | |
counter = 1 | |
print("Ive chosen my number!\n") | |
limit = int(re.sub('[^0-9]+','', ("0"+str(input("How many guesses do you want: ")))), 10) | |
print() | |
win = 0 | |
while counter <= limit: | |
cows = 0 | |
bulls = 0 | |
print("---ROUND " + str(counter) + "/" + str(limit) + "---") | |
guess = str(input("Enter Guess (4 Digit Number): "))+"____" | |
if guess[0] == num2 or guess[0] == num3 or guess[0] == num4: | |
cows = cows + 1 | |
if guess[0] == num1: | |
bulls = bulls + 1 | |
if guess[1] == num1 or guess[1] == num3 or guess[1] == num4: | |
cows = cows + 1 | |
if guess[1] == num2: | |
bulls = bulls + 1 | |
if guess[2] == num1 or guess[2] == num2 or guess[2] == num4: | |
cows = cows + 1 | |
if guess[2] == num3: | |
bulls = bulls + 1 | |
if guess[3] == num1 or guess[3] == num2 or guess[3] == num3: | |
cows = cows + 1 | |
if guess[3] == num4: | |
bulls = bulls + 1 | |
if bulls == 4: | |
win = 1 | |
break | |
else: | |
print("Your guess " + guess[0] + guess[1] + guess[2] + guess[3] + " has:") | |
print("Bulls: %s" % bulls) | |
print("Cows: %s\n"%cows) | |
counter = counter + 1 | |
if win == 1: | |
print("You got it, my number was " + num1 + num2 + num3 + num4 + ".") | |
print() | |
else: | |
print("Sorry, you lost.\nIt was,", num1, num2, num3, num4) | |
print() | |
input("(Press enter to play again)") | |
print() | |
print() | |
print() | |
print("New Game") | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment