创建60个1到99之间的随机实数,保留一位小数
时间: 2024-05-08 14:15:52 浏览: 243
以下是Python代码:
```python
import random
# 生成60个1到99之间的随机实数,保留一位小数
random_numbers = [round(random.uniform(1, 99), 1) for _ in range(60)]
print(random_numbers)
```
输出结果:
```
[51.5, 77.7, 94.5, 63.4, 3.2, 46.8, 63.4, 48.5, 53.0, 31.5, 4.3, 53.4, 17.1, 73.5, 44.1, 21.2, 21.0, 13.7, 54.8, 25.5, 66.7, 28.8, 70.0, 12.9, 16.8, 78.7, 61.3, 21.3, 70.1, 31.6, 64.0, 17.8, 96.0, 79.7, 81.8, 86.7, 25.9, 7.2, 68.2, 23.6, 67.8, 6.3, 93.9, 46.6, 76.3, 67.5, 81.7, 95.5, 15.3, 68.4, 19.8, 53.1, 81.1, 14.2, 47.2, 10.9, 71.1, 54.5, 42.5, 78.1]
```
相关问题
创建60个1到99之间的随机实数,保留一位小数,将其中大于等于平均值的数保存到列表list1
```python
import random
# 生成60个随机实数
nums = [round(random.uniform(1, 99), 1) for i in range(60)]
# 计算平均值
avg = sum(nums) / len(nums)
# 将大于等于平均值的数保存到列表list1
list1 = [num for num in nums if num >= avg]
```
阅读全文