Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def get_cows(player_guess, random_int):
- cows = 0
- counter = 0
- for i in random_int:
- if i == player_guess[counter]:
- cows += 1
- counter += 1
- return cows
- def get_bulls(player_guess, random_int):
- bulls = 0
- counter = 0
- for i in random_int:
- if player_guess[counter] in random_int and i != player_guess[counter]:
- bulls += 1
- counter += 1
- return bulls
- print("Welcome to the Cows and Bulls game!")
- random_int = str(random.randint(1111, 9999))
- player_guess = None
- tries = 0
- while player_guess != random_int:
- player_guess = str(input("Guess the number: "))
- tries += 1
- if player_guess == random_int:
- print("Congratz! It took you {} tries.".format(tries))
- break
- print(str(get_cows(player_guess, random_int)) + " cow/s")
- print(str(get_bulls(player_guess, random_int)) + " bull/s")
Add Comment
Please, Sign In to add comment