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.

pi picoでmicropython その32

Last updated at Posted at 2023-04-06

概要

picoでmicropythonやってみた。
練習問題やってみた。

練習問題

じゃんけんを実装せよ。

サンプルコード

from random import randint

def main():
    hands = {
        0: "gu",
        1: "choki",
        2: "pa"
    }
    rules = {
        (0, 0): "aiko",
        (0, 1): "kati",
        (0, 2): "make",
        (1, 0): "make",
        (1, 1): "aiko",
        (1, 2): "kati",
        (2, 0): "kati",
        (2, 1): "make",
        (2, 2): "aiko",
    }
    while True:
        pc_hand = randint(0, 2)
        user_hand_str = input("0:gu 1:choki 2:pa 3:end\n")
        if user_hand_str == "3":
            print("matane")
            break
        if user_hand_str not in ("0", "1", "2"):
            continue
        user_hand = int(user_hand_str)
        print("you: " + hands[user_hand] + " mi: " + hands[pc_hand] + " -> " + rules[user_hand, pc_hand])
        print("")

実行結果

image.png

以上。

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?