0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paiza.ioでpython その2

Last updated at Posted at 2023-04-04

概要

paiza.ioでpythonやってみた。
じゃんけん、やってみた。

参考にしたページ

サンプルコード

# coding: utf-8
from random import randint

def main():
    hands = {
        0: "グー",
        1: "チョキ",
        2: "パー"
    }
    rules = {
        (0, 0): "あいこ",
        (0, 1): "勝ち",
        (0, 2): "負け",
        (1, 0): "負け",
        (1, 1): "あいこ",
        (1, 2): "勝ち",
        (2, 0): "勝ち",
        (2, 1): "負け",
        (2, 2): "あいこ",
    }
    while True:
        pc_hand = randint(0, 2)
        user_hand_str = input("0:グー 1:チョキ 2:パー 3:やめる\n")
        if user_hand_str == "3":
            print("またね")
            break
        if user_hand_str not in ("0", "1", "2"):
            #print("その数字は対応してません。もう一度やり直してください")
            continue
        user_hand = int(user_hand_str)
        print("ゴンさん : " + hands[user_hand] + "    コンピュータ : " + hands[pc_hand])
        print(rules[user_hand, pc_hand])
        print("")

main()



実行結果

0:グー 1:チョキ 2:パー 3:やめる
ゴンさん : グー    コンピュータ : チョキ
勝ち

0:グー 1:チョキ 2:パー 3:やめる
ゴンさん : チョキ    コンピュータ : パー
勝ち

0:グー 1:チョキ 2:パー 3:やめる
またね

成果物

以上。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?