LoginSignup
0
2

More than 3 years have passed since last update.

じゃんけん問題

Last updated at Posted at 2019-10-24

Pythonじゃんけん問題

import random

def gu():
    if num == 0:
        print("あなたの手:グー, わたしの手:グー")
        print("あいこで")
    elif num == 1:
        print("あなたの手:グー, わたしの手:チョキ")
        print("あなたの勝ちです")
        exit()
    elif num == 2:
        print("あなたの手:グー, わたしの手:パー")
        print("あなたの負けです")
        exit()

def choki():
    if num == 0:
        print("あなたの手:チョキ, わたしの手:グー")
        print("あなたの負けです")
        exit()
    elif num == 1:
        print("あなたの手:チョキ, わたしの手:チョキ")
        print("あいこで")
    elif num == 2:
        print("あなたの手:チョキ, わたしの手:パー")
        print("あなたの勝ちです")
        exit()

def pa():
    if num == 0:
        print("あなたの手:パー, わたしの手:グー")
        print("あなたの勝ちです")
        exit()
    elif num == 1:
        print("あなたの手:パー, わたしの手:チョキ")
        print("あなたの負けです")
        exit()
    elif num == 2:
        print("あなたの手:パー, わたしの手:パー")
        print("あいこで")

def naiyo():
        print("その値は無効です")

while True:
    print("最初はグー、じゃんけん...")
    print("0=グー 1=チョキ 2=パー")
    pon = int(input(''))
    num = random.randint(0,2)

    if pon == 0:
        gu()
    elif pon == 1:
        choki()
    elif pon == 2:
        pa()
    else:
        naiyo()
0
2
3

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
2