# others - 在 python 中，确定3或者5的倍数

def main():

num = input('Insert number:')
output = sumOfMultiples(num)
print(output)

def sumOfMultiples(param):

j = 0
i = 0
for i in range(i, param):
if (i % 3 ==0) or (i % 5 == 0) and (i % 15 != 0):
j = j + i
return j

if __name__ == '__main__':
main()

Traceback (most recent call last):
File"/Users/Soumasish/PycharmProjects/MultiplesOf3And5/Main.py", line 21, in <module>
main()
File"/Users/Soumasish/PycharmProjects/MultiplesOf3And5/Main.py", line 7, in main
output = sumOfMultiples(num)
File"/Users/Soumasish/PycharmProjects/MultiplesOf3And5/Main.py", line 15, in sumOfMultiples
for i in range(i, param):
TypeError: 'str' object cannot be interpreted as an integer

Process finished with exit code 1

def main():
num = int(input('Insert number:'))
output = sumOfMultiples(num)
print(output)

def sumOfMultiples(param):
sum = 0
for i in range(param):
if (i % 3 ==0) or (i % 5 == 0):
sum += i
return sum

num = input('Insert number:')

num是字符串类型，

num_str = input('Insert number:')
output = sumOfMultiples(int(num_str)) #this makes the input string an int first

n=int(input())
a=(n-1)/3
b=(n-1)/5
c=(n-1)/15
ans=(3*a*(a+1)/2)+(5*b*(b+1)/2)-(15*c*(c+1)/2)
print(ans)