daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Nov 8th, 2018 84 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. import random
  2.  
  3.  
  4. def get_cows(player_guess, random_int):
  5.     cows = 0
  6.     counter = 0
  7.  
  8.     for i in random_int:
  9.         if i == player_guess[counter]:
  10.             cows += 1
  11.  
  12.         counter += 1
  13.  
  14.     return cows
  15.  
  16.  
  17. def get_bulls(player_guess, random_int):
  18.     bulls = 0
  19.     counter = 0
  20.  
  21.     for i in random_int:
  22.         if player_guess[counter] in random_int and i != player_guess[counter]:
  23.             bulls += 1
  24.  
  25.         counter += 1
  26.  
  27.     return bulls
  28.  
  29. print("Welcome to the Cows and Bulls game!")
  30.  
  31. random_int = str(random.randint(1111, 9999))
  32. player_guess = None
  33. tries = 0
  34.  
  35. while player_guess != random_int:
  36.     player_guess = str(input("Guess the number: "))
  37.     tries += 1
  38.  
  39.     if player_guess == random_int:
  40.         print("Congratz! It took you {} tries.".format(tries))
  41.         break
  42.  
  43.     print(str(get_cows(player_guess, random_int)) + " cow/s")
  44.     print(str(get_bulls(player_guess, random_int)) + " bull/s")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top