Python出拳游戏
2018-07-19 本文已影响0人
ReiChin_
# coding=utf-8
import random
def fuc_compare():
computer = random.randint(1, 3)
player = int(raw_input("请输入您要出的拳:石头(1) 剪刀(2) 布(3):"))
print "玩家出拳%d---------电脑出拳%d" % (player, computer)
result = computer - player
if result == 0:
# 平局
print "平局请重新出拳"
return fuc_compare()
elif result == 1 or result == -2:
# 玩家胜
return True
elif result == 2 or result == -1:
# 电脑胜
return False
def printResult(result):
if result:
print "玩家胜利啦!"
else:
print "电脑胜利啦!"
print "出拳比赛开始==========="
first = fuc_compare()
print "\n"
second = fuc_compare()
print "\n"
if first == second:
printResult(first)
else:
printResult(fuc_compare())