Напишите игру Rock, paper, scissors, lizard, Spock, основываясь на коде, приведенном в уроке.
Дополнительно выполните такие задания:
1. Реализуйте программу таким образом, чтобы пользователь мог повторить игру столько раз, сколько захочет.
Выведите сообщение типа Try again? и варианты ответа:
Yes ([y]) и No ([n]).
2. По завершению игры выведите общий счет и количество побед (Player VS Computer).
Код к заданию;
import random

print("---------Камень, ножницы, бумага------")
print("3 раунда")
print("\t[к] - камень\n\t[б] - бумага\n\t[н] - ножницы")
player_score = 0
comp_score = 0
player_select = 0
comp_select = 0
print("---------Начало игры------")

for i in range(3):
print("\t------Раунд №" +str(i+1) +"----")
comp_select = random.choice("кбн")

while True:
player_select = input("\tТвой выбор: ")
if (player_select == "к") or (player_select == "б") or (player_select == "н"):
break
else:
print("\tОшибка!!!")

print("\tКомпьютер: " + comp_select)
if comp_select == player_select:
print("\tНичья!!")
elif player_select == "к" and comp_select == "н":
player_score = player_score + 1
print("\tТы победил!!!!!")
elif player_select == "к" and comp_select == "б":
comp_score = comp_score + 1
print("\tКомпьютер победил!!!!!")
elif player_select == "н" and comp_select == "б":
player_score = player_score + 1
print("\tТы победил!!!!!")
elif player_select == "н" and comp_select == "к":
comp_score = comp_score + 1
print("\tКомпьютер победил!!!!!")
elif player_select == "б" and comp_select == "к":
player_score = player_score + 1
print("\tТы победил!!!!!")
elif player_select == "б" and comp_select == "н":
comp_score = comp_score + 1
print("\tКомпьютер победил!!!!!")

print("-------------------------------")
print("------------Результат-----------")
if player_score > comp_score:
print("\tПобеда твоя!!!!!")
elif player_score < comp_score:
print("\tТы проиграл!!!!!")
else:
print("\tНичья!!!!!")

Ответы

Ответ дал: ntram
9

Ответ:

import random

print("---------Камень, ножницы, бумага------")

print("\t[к] - камень\n\t[б] - бумага\n\t[н] - ножницы")

player_score = 0

comp_score = 0

player_select = 0

comp_select = 0

roundd = 0

print("---------Начало игры------")

running = 1

while running:

roundd += 1

print("\t------Раунд №" +str(roundd) +"----")

comp_select = random.choice("кбн")

while True:

 player_select = input("\tТвой выбор: ")

 if (player_select == "к") or (player_select == "б") or (player_select == "н"):

  break

 else:

  print("\tОшибка!!!")

print("\tКомпьютер: " + comp_select)

if comp_select == player_select:

 print("\tНичья!!")

elif player_select == "к" and comp_select == "н":

 player_score += 1

 print("\tТы победил!!!!!")

elif player_select == "к" and comp_select == "б":

 comp_score += 1

 print("\tКомпьютер победил!!!!!")

elif player_select == "н" and comp_select == "б":

 player_score += 1

 print("\tТы победил!!!!!")

elif player_select == "н" and comp_select == "к":

 comp_score += 1

 print("\tКомпьютер победил!!!!!")

elif player_select == "б" and comp_select == "к":

 player_score += 1

 print("\tТы победил!!!!!")

elif player_select == "б" and comp_select == "н":

 comp_score += 1

 print("\tКомпьютер победил!!!!!")

while 1:

 tryagain = input("\tЕще 1 раунд? (y/n)")

 if tryagain == "y":

  break

 elif tryagain == "n":

  running = 0

  break

 else:

  print("\tОшибка: введите y или n")

print("-------------------------------")

print("------------Результат-----------")

if player_score > comp_score:

print("\tПобеда твоя!!!!!")

elif player_score < comp_score:

print("\tТы проиграл!!!!!")

else:

print("\tНичья!!!!!")

Вас заинтересует