|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- count=1
- while count<=10:
- person=int(input('请出拳:[0:石头 1:剪刀 2:布]'))
- computer=random.randint(0,2)
- if person==0 and computer==1: #多条件
- print('厉害了,你赢了')
- pass
- elif person==1 and computer==2:
- print('厉害了,你赢了')
- pass
- elif person==2 and computer==0:
- print('厉害了,你赢了')
- pass
- elif person==computer:
- print('不错,居然是平手')
- pass
- else:
- print('哈哈 我输了')
- pass
- count+=1
复制代码
总是报错,为什么?
请出拳:[0:石头 1:剪刀 2:布]1
Traceback (most recent call last):
File "E:\python\while.py", line 21, in <module>
computer=random.randint(0,2)
NameError: name 'random' is not defined
需要导入random这个库
- import random
- count=1
- while count<=10:
- person=int(input('请出拳:[0:石头 1:剪刀 2:布]'))
- computer=random.randint(0,2)
- if person==0 and computer==1: #多条件
- print('厉害了,你赢了')
- pass
- elif person==1 and computer==2:
- print('厉害了,你赢了')
- pass
- elif person==2 and computer==0:
- print('厉害了,你赢了')
- pass
- elif person==computer:
- print('不错,居然是平手')
- pass
- else:
- print('哈哈 我输了')
- pass
- count+=1
复制代码
|
|