module 'random' has no attribute 'randit'是什么原因,怎么改
时间: 2023-09-24 12:09:52 浏览: 26
这个错误是因为你使用了错误的函数名。正确的函数名是`randint`,而不是`randit`。
要解决这个问题,只需要把代码中的错误函数名改为正确的函数名即可:
```python
import random
# 生成1到10之间的随机整数
num = random.randint(1, 10)
print(num)
```
这样就可以正常运行了。
相关问题
AttributeError: module torch has no attribute randit
AttributeError: module 'torch' has no attribute 'randit' 是因为torch模块中没有名为'randit'的属性。正确的属性名称应该是'randint'。你可以使用torch.randint()来生成一个随机整数。您可以尝试以下代码来解决此问题:
import torch
x = torch.randint(0, 10, (3, 3))
print(x)
module 'numpy.random' has no attribute 'randit'
根据提供的引用内容,可以看出numpy.random模块中没有名为'randit'的属性。可能是用户的输入有误。正确的函数名应该是'randint',而不是'randit'。 'randint'函数用于生成指定范围内的随机整数数组。你可以使用'randint'函数来生成随机整数数组。<span class="em">1</span><span class="em">2</span>
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)