输入一个正数n,输出n的所有因数
时间: 2023-08-06 18:19:53 浏览: 83
好的,我可以帮你解决这个问题。以下是 Python 代码实现:
```python
n = int(input("请输入一个正整数:"))
factors = []
for i in range(1, n+1):
if n % i == 0:
factors.append(i)
print("{}的所有因数为:{}".format(n, factors))
```
你只需要输入一个正整数,程序就会输出它的所有因数。比如,如果你输入 12,程序会输出 [1, 2, 3, 4, 6, 12]。希望能帮到你!
相关问题
输入n和n个整数输出负数,0和正数
以下是Python代码实现:
n = int(input())
nums = list(map(int, input().split()))
negatives = []
zeros = []
positives = []
for num in nums:
if num < 0:
negatives.append(num)
elif num == 0:
zeros.append(num)
else:
positives.append(num)
print(" ".join(map(str, negatives)))
print(" ".join(map(str, zeros)))
print(" ".join(map(str, positives)))
输入n和n个整数,输出负数,0和正数
n = int(input())
nums = list(map(int, input().split()))
negatives = []
zeros = []
positives = []
for num in nums:
if num < 0:
negatives.append(num)
elif num == 0:
zeros.append(num)
else:
positives.append(num)
print(" ".join(map(str, negatives)))
print(" ".join(map(str, zeros)))
print(" ".join(map(str, positives)))
相关推荐
![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)