Форум сайта python.su
0
#Rock_Paper_Scissors print("Welcome to Rock_Paper_Scissors! press 1 for Rock, 2 for Paper and 3 for Scissors" ) #dict gg = {1:"rock", 2:"paper", 3:"scissors"} #user_input x = int(input()) print(f"you chose: {x}, {gg[x]}") #bot_input import random y = int(random.randint(1,3)) print(f"bot chose: {y}, {gg[y]}") #winning conditions if y == x: print("its a tie!") elif y == 1 and x == 2: print("you won!") elif y == 1 and x == 3: print("you lost!") elif y == 2 and x == 3: print("you won!") elif y == 2 and x == 1: print("you lost!") elif y == 3 and x == 1: print("you won!") elif y == 1 and x == 2: print("you lost!")
Офлайн
2
Такой вариант лучше?
#Rock_Paper_Scissors print("Welcome to Rock_Paper_Scissors! press 1 for Rock, 2 for Paper and 3 for Scissors" ) #dict gg = {1:"rock", 2:"paper", 3:"scissors"} #user_input x = int(input()) print(f"you chose: {x}, {gg[x]}") #bot_input import random y = int(random.randint(1,3)) print(f"bot chose: {y}, {gg[y]}") #winning conditions if y == x: print("its a tie!") elif (x-y) == 1 or (x-y) == -2: print("you won!") else: print("you lost!")
Офлайн
857
Код должен быть правильным, понятным и легко меняемым.
Правильным - работать без ошибок.
Понятным - быть без загадок и головоломок.
Легко меняемым - изменение кода в одном месте не должно приводить к необходимости изменения кода в других местах.
tags: code rules
Отредактировано py.user.next (Май 27, 2026 23:59:16)
Офлайн
857
Alex.Pro.И вот мы, например, добавили четвёртое значение во множество значений - какой-нибудь янтарь или велосипед - что происходит с кодом?gg = {1:"rock", 2:"paper", 3:"scissors"}
Alex.Pro.сломается и начнёт неправильно работать, при этом по ней никак не скажешь, что она сломана, потому что чтобы её понять, её надо сначала всю разгадать в уме, прочитать её недостаточно.elif (x-y) == 1 or (x-y) == -2:
Отредактировано py.user.next (Май 27, 2026 23:58:39)
Офлайн
124
import random def get_winner(player, computer): if player == computer: return "Ничья!" # Список выигрышных комбинаций (игрок побеждает компьютер) win_combinations = [ ("камень", "ножницы"), ("ножницы", "бумага"), ("бумага", "камень") ] if (player, computer) in win_combinations: return "Вы выиграли!" return "Вы проиграли!" def main(): choices = ["камень", "ножницы", "бумага"] print("=== Камень, ножницы, бумага ===") print("Введите: камень, ножницы или бумага") print("Для выхода введите 'выход'") while True: player_choice = input("\nВаш выбор: ").lower().strip() if player_choice == "выход": print("Спасибо за игру!") break if player_choice not in choices: print("Ошибка! Введите: камень, ножницы или бумага") continue computer_choice = random.choice(choices) print(f"Компьютер выбрал: {computer_choice}") result = get_winner(player_choice, computer_choice) print(result) if __name__ == "__main__": main()
Отредактировано xam1816 (Май 28, 2026 21:46:42)
Офлайн