Traceback (most recent call last): File "c:/Users/Administrator/Desktop/结界突破.py", line 15, in <module> E=random.randint(1170,700) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\random.py", line 248, in randint return self.randrange(a, b+1) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\random.py", line 226, in randrange raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width)) ValueError: empty range for randrange() (1170, 701, -469)
时间: 2023-07-21 08:10:16 浏览: 208
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误是由于在`random.randint(a, b)`中,参数`a`大于`b`所导致的。在你的代码中,范围是从1170到700,但是`randint`函数要求`a`必须小于等于`b`。为了解决这个问题,你可以交换`a`和`b`的位置,使得`a`小于等于`b`。修改后的代码如下所示:
```python
E = random.randint(700, 1170)
```
阅读全文