产生10个100以内的随机整数放在列表里面
时间: 2023-05-29 07:02:56 浏览: 65
以下是Python代码实现:
```python
import random
numbers = []
for i in range(10):
numbers.append(random.randint(1, 100))
print(numbers)
```
输出:
```
[34, 81, 46, 90, 88, 57, 3, 83, 22, 38]
```
相关问题
c语言如何随机产生10个100以内的整数
以下是C语言随机产生10个100以内整数的代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i, num;
int arr[10];
srand((unsigned)time(NULL)); // 初始化随机数种子
for (i = 0; i < 10; i++) {
num = rand() % 101; // 产生0~100之间的随机整数
arr[i] = num;
printf("%d ", num);
}
printf("\n");
return 0;
}
```
用程序编写一个包含10个100以内随机整数的列表
Python代码:
```python
import random
# 生成包含10个100以内随机整数的列表
lst = [random.randint(1, 100) for _ in range(10)]
print(lst) # 输出列表
```
输出结果:
```
[45, 23, 96, 4, 68, 100, 89, 45, 94, 34]
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)