Hej, od około tygodnia uczę się pythona, napisałem prostą gierkę w papier, kamień i nożyce. Polega na tym, że komputer losuje liczbę, a my staramy się z nim wygrać. Gra jest do 3 punktów. Co myślicie o takim kodzie? Pewnie dałoby się to jeszcze bardziej uprościć.
from random import randint
from time import sleep
# listy
lista = {1: 'papier', 2:'kamien', 3:'nozyce'}
choices = ['papier', 'kamien', 'nozyce']
# nagłówek
print('Papier, kamien czy nozyce?')
# zmienne punktów użyt. i komputera
points_user = 0
points_computer = 0
# funkcja zliczania punktów
def punkty(points_user, points_computer):
print('Twoje punkty: ', points_user)
print('Punkty komputera: ', points_computer)
# GRA
while points_user != 3 and points_computer != 3:
x = randint(1, 3)
user_choice = True
while user_choice:
user = input('Podaj swój wybór: ')
if user in choices:
user_choice = False
#
# PAPIER
#
if user == 'papier':
if x == 1:
sleep(1)
punkty(points_user, points_computer)
print('\n')
print('Remis! Wybraliśmy to samo')
print('\n')
if x == 2:
sleep(1)
points_user = points_user + 1
punkty(points_user, points_computer)
print('\n')
print(f'O nie! Przegrałem, mój wybór to {lista[x]}')
print('\n')
if x == 3:
sleep(1)
points_computer = points_computer + 1
punkty(points_user, points_computer)
print('\n')
print(f'Haa! Wygrałem! Mój wybór to {lista[x]}')
print('\n')
#
# KAMIEN
#
if user == 'kamien':
if x == 2:
sleep(1)
punkty(points_user, points_computer)
print('\n')
print('Remis! Wybraliśmy to samo')
print('\n')
if x == 3:
sleep(1)
points_user = points_user + 1
punkty(points_user, points_computer)
print('\n')
print(f'O nie! Przegrałem, mój wybór to {lista[x]}')
print('\n')
if x == 1:
sleep(1)
points_computer = points_computer + 1
punkty(points_user, points_computer)
print('\n')
print(f'Haa! Wygrałem! Mój wybór to {lista[x]}')
print('\n')
#
# NOZYCE
#
if user == 'nozyce':
if x == 3:
sleep(1)
punkty(points_user, points_computer)
print('\n')
print('Remis! Wybraliśmy to samo')
print('\n')
if x == 1:
sleep(1)
points_user = points_user + 1
punkty(points_user, points_computer)
print('\n')
print(f'O nie! Przegrałem, mój wybór to {lista[x]}')
print('\n')
if x == 2:
sleep(1)
points_computer = points_computer + 1
punkty(points_user, points_computer)
print('\n')
print(f'Haa! Wygrałem! Mój wybór to {lista[x]}')
print('\n')
# WYŚWIETLENIE WYNIKU
if points_user == 3:
print('BRAWO WYGRAŁEŚ!')
print('')
else:
print('Niestety komputer wygrał')
print('')```