Advertisement
viking_unet

bulls game

Jun 21st, 2020
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import random
  2.  
  3. x1 = random.choice(range(1, 10))
  4. x2 = random.choice([x for x in range(0,10) if x not in [x1]])
  5. x3 = random.choice([x for x in range(0,10) if x not in [x1, x2]])
  6. x4 = random.choice([x for x in range(0,10) if x not in [x1, x2, x3]])
  7.  
  8. number = '%s%s%s%s' % (x1, x2, x3, x4)
  9.  
  10. print(number)
  11.  
  12. while True:
  13.     user_number = input('введите загаданное число: ').strip()
  14.     if len(set(list(user_number))) < 4:
  15.         print('вводить можно только 4-х значные числа с неповторяющимися цифрами!')
  16.         continue
  17.     if user_number == number:
  18.         print('Вы выиграли!')
  19.         break
  20.     cows, bulls = 0, 0
  21.     cows = len(set(list(number)).intersection(list(user_number)))
  22.     bulls = len([x for x in zip(list(number), list(user_number)) if x[0] == x[1]])
  23.     print('коров %s быков %s' % (cows, bulls))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement