有一组彩色小球24,26,37,88,65,13,66,75,21,33,76共11个,按照从小到大的顺序进行排序,单数和复数分组输出,且输出的值不能是7和11的倍数。请根据大家学习的知识点,至少用两
时间: 2024-06-13 20:08:50 浏览: 17
```python
# 将球按照从小到大的顺序排序
balls = [24, 26, 37, 88, 65, 13, 66, 75, 21, 33, 76]
balls.sort()
# 单数和复数分组输出,且输出的值不能是7和11的倍数
odd_balls = []
even_balls = []
for ball in balls:
if ball % 2 == 1 and ball % 7 != 0 and ball % 11 != 0:
odd_balls.append(ball)
elif ball % 2 == 0 and ball % 7 != 0 and ball % 11 != 0:
even_balls.append(ball)
print("Odd balls:", odd_balls)
print("Even balls:", even_balls)
```
```python
# 将球按照从小到大的顺序排序
balls = [24, 26, 37, 88, 65, 13, 66, 75, 21, 33, 76]
balls.sort()
# 单数和复数分组输出,且输出的值不能是7和11的倍数
odd_balls = [ball for ball in balls if ball % 2 == 1 and ball % 7 != 0 and ball % 11 != 0]
even_balls = [ball for ball in balls if ball % 2 == 0 and ball % 7 != 0 and ball % 11 != 0]
print("Odd balls:", odd_balls)
print("Even balls:", even_balls)
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)