Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- random.seed()
- cows, bulls, play = 0, 0, 1
- code = []
- for i in range(4):
- code.append(str(random.randint(0,9)))
- print(code)
- while play == 1:
- guess = list(input("Guess the four digits: "))
- for i, letters in enumerate(code):
- incremented = 0
- similarity_range = []
- for j in range(len(code)):
- if guess[j] == letters:
- similarity_range.append(j)
- for k in range(len(code)):
- if incremented == 1:
- break
- if guess[k] == letters:
- for t in similarity_range:
- if k == t:
- cows += 1
- incremented = 1
- break
- if k == 3:
- bulls += 1
- print("{} cows, {} bulls".format(cows, bulls))
- if cows == 4:
- print("Congratulations!")
- break
- else:
- cows = 0
- bulls = 0
- play = int(input("Press 1 to keep guessing: "))
Add Comment
Please, Sign In to add comment