打印一个函数i i>0,从0开始求和,包括1~i的每个整数x
如果x能被三整除但不能被五整除,则加上数值3x
如果不能被三整出但能被五整除,则加上数值5x
如果不能被三和五整除则不添加任何值
输入一个数,只需要输出结果
代码如下如有帮助请点击一下采纳谢谢;
def pri(num):
temp = ''
for i in range(1, num+1):
if i%3==0 and i%5!=0:
temp = temp + str(i) + '*3' + '+'
elif i%5==0 and i%3!=0:
temp = temp +str(i) + '*5' + '+'
else:
temp = temp + str(i) + '+'
print(temp[:-1])
pri(10)
num = int(input("请输入一个数:"))
f = ''
for i in range(1, num + 1):
if i % 3 == 0 and i % 5 != 0:
f += f'{str(i)}*3+'
elif i % 5 == 0 and i % 3 != 0:
f += f'{str(i)}*5+'
else:
f += f'{str(i)}+'
print(f[:-1])
total_count = 0
res_str = ""
input_num = int(input("请输入一个整数:"))
for i in range(1, input_num):
if i % 3 == 0 and i % 5 != 0:
res_str = res_str + f"{i}3+"
total_count = total_count + (i3)
elif i % 3 != 0 and i % 5 == 0:
res_str = res_str + f"{i}*5+"
total_count = total_count + (i * 5)
else:
res_str = res_str + f"{i}+"
total_count = total_count + i
print(f"{res_str[:-1]}={total_count}")