今日のアウトプット06/02
#モジュールのインポート
import random
#変数の定義
hands = ['グー', 'チョキ', 'パー']
syouhai_hantei = 'kkkkk'
#関数の定義
#プレイヤーのハンド(数値入力)
def player_hand():
print('[0:グー, 1:チョキ, 2:パー]')
input_hand = int(input('上記のハンドの数字を入力して下さい:'))
return hands[input_hand]
#CPのハンド(ランダム)
def cp_hand():
return hands[random.randint(0, 2)]
#勝敗判定の関数
def syouhai(ph,ch):
global syouhai_hantei
if ph == ch :
print('引き分け')
elif ph == 'グー' and ch == 'チョキ' or \
ph == 'チョキ' and ch == 'パー' or \
ph == 'パー' and ch == 'グー' :
print('勝ち')
if syouhai_hantei == 'プレイヤーの1勝':
syouhai_hantei = '2連続勝利'
else :
syouhai_hantei = 'プレイヤーの1勝'
return syouhai_hantei
else :
print('負け')
if syouhai_hantei == 'コンピューターの1勝' :
syouhai_hantei = '2連続敗北'
else :
syouhai_hantei = 'コンピューターの1勝'
return syouhai_hantei
print(syouhai(player_hand(),cp_hand()))
ーーーーーーーーーーーーーーーーーーーーーー
[0:グー, 1:チョキ, 2:パー]
上記のハンドの数字を入力して下さい:1
引き分け
None
ーーーーーーーーーーーーーーーーーーーーーーー
printで囲うとNoneまで出力されてしまう。
この記事が気に入ったらサポートをしてみませんか?