LoginSignup
0
0

More than 5 years have passed since last update.

pythonでじゃんけん作ってみた

Last updated at Posted at 2019-04-02
jyanken.py
import random
dic = {"a": "グー", "b": "チョキ", "c": "パー"}

print("じゃんけん")
print("a=グー b=チョキ c=パー")
user_hand = input(">>>  ")

user_choice = dic[user_hand]

choice_list = ["a", "b", "c"]
pc = dic[random.choice(choice_list)]

draw = 'あいこ'
win = 'あなたの勝ち'
lose = 'あなたの負け'

if user_choice == pc:
    judge = draw
else:
    if user_choice == "グー":
        if pc == "チョキ":
            judge = win
        else:
            judge = lose

    elif user_choice == "チョキ":
        if pc == "パー":
            judge = win
        else:
            judge = lose

    else:
        if pc == "グー":
            judge = win
        else:
            judge = lose

print("あなた:" + user_choice)
print("コンピュータ:" + pc)
print("結果:" + judge)
0
0
2

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