为什么我计算总次数的时候第一次老是计算不上,然后运行结果次数老是在出的石头剪刀布前面,我想让石头剪刀布在次数前边
**
scissor (0),rock (1), paper (2): 1
The computer is scissor. You are rock. You won.
scissor (0), rock (1), paper (2): 2
The computer is paper. You are paper too. It is a draw.
程序编辑:
"""
数据:电脑随机的 com 用户输入的 usr
步骤:
1.提示用户输入0 1 2
2.电脑随机产生0 1 2
3.对比
石头
1
剪刀 布
0 2
0 - 1 = -1
1 - 2 = -1
2 - 0 = 2
"""
import random
com = random.randint(0, 2)
usr = int(input("剪刀(0),石头(1),布(2):"))
com_str = ""
usr_str = ""
if com == 0:
com_str = "剪刀"
elif com == 1:
com_str = "石头"
else:
com_str = "布"
if usr == 0:
usr_str = "剪刀"
elif usr == 1:
usr_str = "石头"
else:
usr_str = "布"
if com == usr:
print("玩家是%s,电脑是%s,是一个平局" % (usr_str, com_str))
elif usr - com == -1 or usr - com == 2:
print("玩家是%s,电脑是%s,玩家输" % (usr_str, com_str))
else:
print("玩家是%s,电脑是%s,玩家赢" % (usr_str, com_str))
测试:
J:\python\python.exe K:/python2020.8.4练习/PythonCode/day1/day02/28.py
剪刀(0),石头(1),布(2):3
玩家是布,电脑是石头,玩家输
Process finished with exit code 0
Demo29
**