Commit 99a19c1c by BellCodeEditor

save project

parent a0cbfb52
Showing with 49 additions and 2 deletions
# 玩家出拳
\ No newline at end of file
player = input("玩家出拳:")
print("玩家出拳" + player)
\ No newline at end of file
#coding=utf-8
import random
exit_flag = False #设置flag用于break跳出两层循环,或者自定义异常也行,try:, except。
dic = {}
dic[0] = '剪刀'
dic[1] = '石头'
dic[2] = '布'
while True:
humanStr = input("请输入[0:剪刀 1:石头 2:布] ")
if humanStr.isdigit() and (int(humanStr) in [0,1,2]): #如果输入的是数字,并且在0,1,2中
human = int(humanStr)
windows = random.randint(0, 2)
print ("你出的是%s,电脑出的是%s" % (dic[human],dic[windows]))
if (human == 0 and windows == 2) or (human == 1 and windows == 0) or (human == 2 and windows == 1):
print("祝贺你,你赢了!")
oncemore = input("你想再来一局吗? y(Y) or n(N) ")
elif human == windows:
print("平局")
oncemore = input("你想再来一局吗? y(Y) or n(N) ")
else:
print("不好意思,你输了")
oncemore = input("你想再来一局吗? y(Y) or n(N) ")
while True:
if oncemore == 'y' or oncemore == 'Y':
break
elif oncemore == 'n' or oncemore == 'N':
exit_flag = True
break #跳出内层循环,并且设置flag
else:
oncemore = input("你想再来一局吗? y(Y) or n(N) ")
if exit_flag == True:
break #跳出层循环,结束程序
else:
print ("请重新输入!")
pass
\ No newline at end of file
player = input("玩家出拳:")
player = input("玩家出拳:")
print("玩家出拳" + player)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment