Вопрос задан 04.06.2023 в 03:44. Предмет Информатика. Спрашивает Азаренко Анастасия.

Напишите игру 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Ничья!!!!!")
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Латыпов Денис.

Ответ:

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Ничья!!!!!")

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Вот модифицированный код игры "Камень, ножницы, бумага, ящерица, Спок", который учитывает ваши дополнительные требования:

python
import 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', игра завершится.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос