LoginSignup
0
0

More than 1 year has passed since last update.

【Python】ジャンケンのプログラムを作ってみた!

Last updated at Posted at 2021-09-09

 Pythonを勉強し始めて1週間が経過したので、何か簡単なプログラムを作ってみようと考え、ジャンケンのプログラムを作ってみました。

import random

while True:
    jan = ["グー","チョキ","パー"]
    cpu = random.choice(jan)
    user = int(input("グーだったら0、チョキだったら1、パーだったら2を入力してください:"))
    print("あなた:" + jan[user])
    print("CPU:" + cpu)

    if jan[user] == cpu:
        print("あいこです")
        continue
    else:
        if cpu == jan[user - 1]:
            print("負けです")
            break
        else:
            print("勝ちです")
            break

 出力結果は以下のような形です。

グーだったら0、チョキだったら1、パーだったら2を入力してください:0
あなた:グー
CPU:グー
あいこです
グーだったら0、チョキだったら1、パーだったら2を入力してください:2
あなた:パー
CPU:グー
勝ちです

 何も調べずに自分の知識の範囲内でこのようなコードを書きましたが、ジャンケンの仕組みやPythonのメソッドをもっと考えれば、より良いコードが書けると思いますので、ご意見いただけるとありがたいです。


0
0
4

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