Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- attempts = 0
- while True:
- num = str(random.randrange(1000,10000))
- count = [num.count(i) for i in num if num.count(i)>1]
- if not count: break
- while True:
- guess = input()
- bulls, cows = 0,0
- attempts += 1
- if [guess.count(j) for j in guess if guess.count(j)>1]:
- print("Duplicate number entered, please try again")
- continue
- for idx,dgt in enumerate(guess):
- if dgt == num[idx]:
- bulls+=1
- continue
- elif dgt in num:
- cows+=1
- continue
- if bulls==4: print(f"Number : {num}\nAttempts : {attempts}")
- else: print(f"{bulls}A {cows}B")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement