我写了一个08_剪刀石头布.py的文件。
08_剪刀石头布.py的内容是:
import random
a = 1
computer = 1
computer = random.randint(0,2)
while a == 1:
computer = random.randint(0,2)
plays = input("请输入0 剪刀 1 石头 2 布 (3 退出):")
if plays <= "3" and plays >="0":
plays = int(plays)
if plays < 3 and plays >=0:
if plays == 0:
out_plays = "剪刀"
elif plays == 1:
out_plays = "石头"
elif plays == 2:
out_plays = "布"
if computer == 0:
out_computer = "剪刀"
elif computer == 1:
out_computer = "石头"
elif plays == 2:
out_computer = "布"
print("玩家:%s"%out_plays)
print("电脑:%s"%out_computer)
if (plays == 1 and computer == 0) or (plays == 2 and computer == 1) or (plays == 0 and computer == 2):
print("你赢了!")
elif plays == computer:
print("平局!")
elif (plays == 0 and computer == 1) or (plays == 1 and computer == 2) or (plays == 2 and computer == 0):
print("你输了!")
elif plays == 3:
break
else:
print("输入无效,请重新输入")
else:
print("输入无效,请重新输入")
但不知到为什么我用deepin15.4.1桌面版的终端运行是有时出错了。而有时有没有错。
出错是这样的:
x@X:~/Desktop/4$ python3 08_剪刀石头布.py
请输入0 剪刀 1 石头 2 布 (3 退出):1
玩家:石头
Traceback (most recent call last):
File "08_剪刀石头布.py", line 28, in <module>
print("电脑:%s"%out_computer)
NameError: name 'out_computer' is not defined
x@X:~/Desktop/4$ sublime-text-dev 08_剪刀石头布.py
不知是系统问题、软件问题,还是硬件问题。不知能不能修复这个bug?如何修复?
print("谢谢!"*10) |
|