bin elif 重新 inpu import while user 猜拳游戏
- # ! /usr/bin / python#coding = utf - 8import randomxd = {
- 1 : '剪刀',
- 2 : '石头',
- 3 : '布'
- }
- blist = ['剪刀', '石头', '布']#print xd[1];
- c = raw_input('局数: ') if str.isdigit(c) : c = int(c) compute = 0 user = 0 i = 1
- while c: s = int(random.uniform(1, 4))#s = 3#print xd[s]#print s m = raw_input('请输入石头剪刀布: ') if (m == '剪刀') : a = 1
- if (m == '石头') : a = 2
- if (m == '布') : a = 3
- if (m in blist) : if (a == s) : print'第' + str(i) + '局平局\n电脑出了: ' + xd[s] c -= 1;
- i += 1 elif(a == 1 and s == 2) or(a == 2 and s == 3) or(a == 3 and s == 1) : print'第' + str(i) + '局电脑赢了\n电脑出了: ' + xd[s] c -= 1;
- compute += 1;
- i += 1
- else: print "第" + str(i) + '局你赢了\n电脑出了: ' + xd[s] c -= 1;
- user += 1;
- i += 1
- if c == 0 and user == compute: print'进入加时赛'c += 1
- else: print'重新输入: 'print'玩家vs电脑\n' + str(user) + ': ' + str(compute);'''
- if (user == compute) : print'最终玩家和电脑打平'c += 1;
- i += 1'''
- if (user > compute) : print'最终玩家获胜'
- else: print'最终电脑获胜'
- else: print'请输入数字'
python - 训练 1_猜拳游戏
来源: http://www.bubuko.com/infodetail-2075881.html