import random winlist = [[‘石头,剪刀‘],[‘剪刀,布‘],[‘布,拳头‘]] choicelist = (‘石头‘,‘剪刀‘,‘布‘) promt = ‘‘‘请选择“石头,剪刀,布”: 0.石头 1.剪刀 2.布 3.退出 输入数字1-4即可,请输入:‘‘‘ while True: userchoicenum = int(input(promt)) if userchoicenum== 3: break userchoice = choicelist[userchoicenum] comchoice = random.choice(choicelist) bothchoice = [userchoice,comchoice] if userchoice == comchoice: print(‘ 平局‘) break elif bothchoice in winlist: print(‘ \n 你赢了!\n 你选择的是:%s 计算机选择的是:%s‘ % (userchoice,comchoice)) break else: print(‘ \n 计算机赢了!\n 你选择的是:%s 计算机选择的是:%s‘ % (userchoice,comchoice)) break
时间: 2024-10-14 09:49:23