Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- x1 = random.choice(range(1, 10))
- x2 = random.choice([x for x in range(0,10) if x not in [x1]])
- x3 = random.choice([x for x in range(0,10) if x not in [x1, x2]])
- x4 = random.choice([x for x in range(0,10) if x not in [x1, x2, x3]])
- number = '%s%s%s%s' % (x1, x2, x3, x4)
- print(number)
- while True:
- user_number = input('введите загаданное число: ').strip()
- if len(set(list(user_number))) < 4:
- print('вводить можно только 4-х значные числа с неповторяющимися цифрами!')
- continue
- if user_number == number:
- print('Вы выиграли!')
- break
- cows, bulls = 0, 0
- cows = len(set(list(number)).intersection(list(user_number)))
- bulls = len([x for x in zip(list(number), list(user_number)) if x[0] == x[1]])
- print('коров %s быков %s' % (cows, bulls))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement