0
0

More than 1 year has passed since last update.

[Rock, Paper, Scissors] 古典的なじゃんけんゲームの実装(Python)

Posted at

じゃんけんゲームの実装(簡単)

実装例

rock_paper_scissors.py
import random

options = ["rock", "paper", "scissors"]

while True:
    computer_choice = random.choice(options)
    player_choice = input("Rock, paper, or scissors? ").lower()
    if player_choice == "quit":
        break
    elif player_choice in options:
        if player_choice == computer_choice:
            print("Tie!")
        elif player_choice == "rock" and computer_choice == "scissors":
            print("You win!")
        elif player_choice == "paper" and computer_choice == "rock":
            print("You win!")
        elif player_choice == "scissors" and computer_choice == "paper":
            print("You win!")
        else:
            print("Computer wins!")
    else:
        print("Invalid option.")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0