gpt4 book ai didi

python - 通过用逗号分隔在同一行中打印一些数字

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:27 25 4
gpt4 key购买 nike

我想打印数字“(input_number) 的因数是” 1,2,5,10,50但打印时多加了一个逗号,如下所示: 1,2,3,4,5,

input_number = int(input("Enter A Number Please: "))
factors = []
for divisor in range(1, input_number+1):
mod = input_number % divisor
if mod == 0:
factors.append(divisor)
print("Factors of %i are - " % input_number)
for element in factors:
print(element, end=",")

最佳答案

你可以试试这个:

input_number = int(input("Enter A Number Please: "))
factors = []
for divisor in range(1, input_number+1):
mod = input_number % divisor
if mod == 0:
factors.append(divisor)
print("Factors of %i are - " % input_number+ ",".join(str(row) for row in factors))

关于python - 通过用逗号分隔在同一行中打印一些数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54899678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com