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?

じゃんけん.py

Posted at

乱数でじゃんけんに勝つ

相手の傾向から次の勝利を予想する。

main.py
import random
gu = 0
choki = 0
pa = 0
num = 0
gu_p = 1
choki_p = 1
pa_p = 1
up_p = 0.1
dict = ['gu','cho','pa']
while True :
    if num != 0:
        res = input("勝or負(w / l) : ")
        if res == 'w' or res == 'l':
            pass
        else:
            res = random.choice(['w','l'])
        if gu == 1:
            gu = 0
            if res == 'w':
                gu_p += up_p
            else:
                if gu_p > up_p * 1.1:
                    gu_p -= up_p
                else:
                    pass
        elif choki == 1:
            choki = 0
            if res == 'w':
                choki_p += up_p
            else:
                if choki_p > up_p * 1.1:
                    choki_p -= up_p
                else:
                    pass
        elif pa == 1:
            pa = 0
            if res == 'w':
                pa_p += up_p
            else:
                if pa_p > up_p * 1.1:
                    pa_p -= up_p
                else:
                    pass
        else:
            pass
    w = [gu_p,choki_p,pa_p]
    val = random.choices(dict, k = 1, weights = w)
    val = val[0]
    if val == 'gu':
        gu += 1
        print('グー')
    elif val == 'cho':
        choki += 1
        print('チョキ')
    elif val == 'pa':
        pa += 1
        print('パー')
    else:
        pass
    #print([gu_p,choki_p,pa_p])
    num += 1
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?