zdjecie_kamien_papier_nozyce_1

Następnym program jaki napisałem jest gra: Kamień Papier Nożyce. Ma ona dwa tryby: łatwy i trudny. Łatwy jest oparty na losowym wybieraniu narzędzi: kamienia, papieru lub nożyc. Trudny natomiast analizuje ile razy wybrałeś to samo narzędzie i wybiera wtedy narzędzie przeciwne. W czasie pisania tej mini gry nauczyłem się:

- obsługiwania modułu random, czyli modułu losującego dowolną liczbę z zakresu jaki mu wyznaczę (import random).

import random
text0 = 'WYGRYWASZ'
text1 = 'PRZEGRYWASZ'
text2 = 'REMIS'
n1 = 'kamień'
n2 = 'papier'
n3 = 'nożyce'
user = 0
comp = 0
i = 1
z = 1
k = 1
l1 = 0
level = ''
replay = ''
answer = ''
operation = ''
print('START')
print('Wybież poziom trudności:'
'\t łatwy'
'\t\t trudny'
'\n \n \t UWAGA pisz małymi literami')
level = input()
if level == 'łatwy':
while True:
r = random.randint(1, 3)
if r == 1: answer = 'kamień'
if r == 2: answer = 'papier'
if r == 3: answer = 'nożyce'
print('Masz cztery opcje: \n n1 = kamień \n n2 = papier')
print('\n n3 = nożyce \n nic (ENTER) = koniec gry')
operation = str(input())
if not operation == 'n1':
if not operation == 'n2':
if not operation == 'n3':
if not operation == '':
print('ERROR Błędna odpowiedź')
print(user,'','vs','',comp)

if operation == 'n1':
replay = 'kamień'
if operation == 'n2':
replay = 'papier'
if operation == 'n3':
replay = 'nożyce'
if replay == 'kamień' and answer == 'kamień':
user += 0.5
comp += 0.5
print(text2)
print(answer)
if replay == 'kamień' and answer == 'papier':
comp += 1
print(text1)
print(answer)
if replay == 'kamień' and answer == 'nożyce':
user += 1
print(text0)
print(answer)
if replay == 'papier' and answer == 'kamień':
user += 1
print(text0)
print(answer)
if replay == 'papier' and answer == 'papier':
user += 0.5
comp += 0.5
print(text2)
print(answer)
if replay == 'papier' and answer == 'nożyce':
comp += 1
print(text1)
print(answer)
if replay == 'nożyce' and answer == 'kamień':
comp += 1
print(text1)
print(answer)
if replay == 'nożyce' and answer == 'papier':
user += 1
print(text0)
print(answer)
if replay == 'nożyce' and answer == 'nożyce':
comp += 0.5
user += 0.5
print(text2)
print(answer)
if operation == '':
if user > comp:
print('Wygrałeś grę!')
print(user, 'vs', comp)
if user < comp:
score = str(user) + ' vs' + str(comp)
print('Przegrałeś grę!')
print(user, 'vs', comp)
if user == comp:
score = str(user) + ' vs ' + str(comp)
print('REMIS')
print(user, 'vs', comp)
break
if level == 'trudny':
while True:
r = random.randint(1, 3)
if r == 1: answer = 'kamień'
if r == 2: answer = 'papier'
if r == 3: answer = 'nożyce'
if operation == 'kamień':
answer = 'nożyczki'
if operation == 'papier':
answer = 'kamień'
if operation == 'nożyczki':
answer = 'papier'
print('Masz cztery opcje: \n n1 = kamień \n n2 = papier')
print('\n n3 = nożyce \n nic (ENTER) = koniec gry')
operation = str(input())
if not operation == 'n1':
if not operation == 'n2':
if not operation == 'n3':
if not operation == '':
print('ERROR Błędna odpowiedź')
print(user,'','vs','',comp)
break
if operation == 'n1':
replay = 'kamień'
i += 1
if operation == 'n2':
replay = 'papier'
z += 1
if operation == 'n3':
replay = 'nożyce'
k += 1

if i == 2:
answer = 'papier'
i = 0
if z == 2:
answer = 'nożyce'
z = 0
if k == 2:
answer = 'kamień'
k = 0

if replay == 'kamień' and answer == 'kamień':
user += 0.5
comp += 0.5
print(text2)
print(answer)
if replay == 'kamień' and answer == 'papier':
comp += 1
print(text1)
print(answer)
if replay == 'kamień' and answer == 'nożyce':
user += 1
print(text0)
print(answer)
if replay == 'papier' and answer == 'kamień':
user += 1
print(text0)
print(answer)
if replay == 'papier' and answer == 'papier':
user += 0.5
comp += 0.5
print(text2)
print(answer)
if replay == 'papier' and answer == 'nożyce':
comp += 1
print(text1)
print(answer)
if replay == 'nożyce' and answer == 'kamień':
comp += 1
print(text1)
print(answer)
if replay == 'nożyce' and answer == 'papier':
user += 1
print(text0)
print(answer)
if replay == 'nożyce' and answer == 'nożyce':
comp += 0.5
user += 0.5
print(text2)
print(answer)
if operation == '':
if user > comp:
print('Wygrałeś grę!')
print(user, 'vs', comp)
if user < comp:
score = str(user) + ' vs' + str(comp)
print('Przegrałeś grę!')
print(user, 'vs', comp)
if user == comp:
score = str(user) + ' vs ' + str(comp)
print('REMIS')
print(user, 'vs', comp)
break

print('KONIEC GRY')