
Напишите игру 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Ничья!!!!!")

Ответы на вопрос

Ответ:
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Ничья!!!!!")



Вот модифицированный код игры "Камень, ножницы, бумага, ящерица, Спок", который учитывает ваши дополнительные требования:
pythonimport random
def play_game():
print("---------Камень, ножницы, бумага, ящерица, Спок------")
print("3 раунда")
print("\t[к] - камень\n\t[б] - бумага\n\t[н] - ножницы\n\t[я] - ящерица\n\t[с] - Спок")
player_score = 0
comp_score = 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 in ["к", "б", "н", "я", "с"]:
break
else:
print("\tОшибка!!!")
print("\tКомпьютер: " + comp_select)
if comp_select == player_select:
print("\tНичья!!")
elif (
(player_select == "к" and comp_select in ["н", "я"]) or
(player_select == "б" and comp_select in ["к", "я"]) or
(player_select == "н" and comp_select in ["б", "с"]) or
(player_select == "я" and comp_select in ["б", "с"]) or
(player_select == "с" and comp_select in ["к", "н"])
):
player_score += 1
print("\tТы победил!!!!!")
else:
comp_score += 1
print("\tКомпьютер победил!!!!!")
print("-------------------------------")
print("------------Результат-----------")
print("\tТвой счет: " + str(player_score))
print("\tСчет компьютера: " + str(comp_score))
if player_score > comp_score:
print("\tПобеда твоя!!!!!")
elif player_score < comp_score:
print("\tТы проиграл!!!!!")
else:
print("\tНичья!!!!!")
def play_again():
while True:
choice = input("Try again? (Yes [y]/No [n]): ")
if choice.lower() in ["y", "n"]:
return choice.lower() == "y"
else:
print("Неверный выбор. Пожалуйста, выберите 'y' или 'n'.")
play = True
while play:
play_game()
play = play_again()
Теперь после завершения игры будет предложено пользователю сыграть еще раз. Если пользователь введет 'y', игра будет повторяться, а если введет 'n', игра завершится.


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili