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 3 years have passed since last update.

じゃんけんゲーム

Last updated at Posted at 2021-11-21
jyanken.py
import random

count = 1
jyanken = ['グー', 'チョキ', 'パー']

def kati():
    print('-----------------------------------')
    print('あなたの勝ち')
    print('あなたは' + jyanken[int_te] + '相手は' + jyanken[aite])
    print(f'{count}回目で勝負がつきました')
    
def make():
    print('-----------------------------------')
    print('相手の勝ち')
    print('あなたは' + jyanken[int_te] + '相手は' + jyanken[aite])
    print(f'{count}回目で勝負がつきました')

#最初に手を決める部分、グーは1、チョキは2、パーは3に変換
while True:
    te = input('手を決めて下さい:グー=g、チョキ=c、パー=p')
    if te == 'g':
        int_te = 0

    elif te == 'c':
        int_te = 1

    elif te == 'p':
        int_te = 2

    else:
        print('間違った入力がされました。')
        count += 1
        continue

    #相手の手をランダムで決める
    aite = random.randint(0,2)
    
    if int_te - aite == 0:
        print('あいこ')
        count += 1
        continue
    
    elif int_te == 0 and aite == 1:
        kati()
        break
    elif int_te == 0 and aite == 2:
        make()
        break
    elif int_te == 1 and aite == 0:
        make()
        break
    elif int_te == 1 and aite == 2:
        kati()
        break
    elif int_te == 2 and aite == 0:
        kati()
        break
    else:
        make()
        break
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?