Advertisement
Guest User

Kamień, Papier, Nożyce

a guest
May 1st, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. import random
  2. import sys
  3.  
  4. symbols = ['Papier', 'Kamień', 'Nożyce']
  5.  
  6. def start_game():
  7.     print('Witaj w grze Kamień, papier, nożyce.')
  8.     player_choice = input('Podaj symbol(Kamień[K], Papier[P], Nożyce[N]): ')
  9.     cpu_choice = random.choice(symbols)
  10.     print('Twoj przeciwnik wybral:', cpu_choice)
  11.  
  12.     who_win(cpu_choice ,player_choice)
  13.  
  14. def who_win(cpu_choice, player_choice):
  15.     if cpu_choice == player_choice:
  16.         result = 'tie'
  17.     if player_choice == 'K':
  18.         if cpu_choice == 'Papier':
  19.             result = 'lose'
  20.         elif cpu_choice == 'Nożyce':
  21.             result = 'win'
  22.     if player_choice == 'P':
  23.         if cpu_choice == 'Kamień':
  24.             result = 'win'
  25.         elif cpu_choice == 'Nożyce':
  26.             result = 'lose'
  27.     if player_choice == 'N':
  28.         if cpu_choice == 'Kamień':
  29.             result = 'lose'
  30.         elif cpu_choice == 'Papier':
  31.             result = 'win'
  32.  
  33.     wynik(result)
  34.  
  35. def wynik(result):
  36.     player_score = 0
  37.     cpu_score = 0
  38.     if result == 'tie':
  39.         print('Remis.')
  40.     elif result == 'lose':
  41.         print('Przegrałeś')
  42.         cpu_score += 1
  43.     elif result == 'win':
  44.         print('Wygrałeś')
  45.         player_score += 1
  46.  
  47.     print('Komputer:',cpu_score, 'Gracz:', player_score)
  48.     play_again()
  49.  
  50. def play_again():
  51.     play_again = input('Jeżeli chcesz zagrać ponownie napisz T, w przeciwnym razie napisz N: ')
  52.     if play_again == 'T':
  53.         print('**********************************************')
  54.         start_game()
  55.     elif play_again == 'N':
  56.         sys.exit()
  57.  
  58. start_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement