如何为Python的给定函数的特定参数设置无限迭代?

时间:2019-02-01 09:48:39

标签: python

Sum Of Multiples Program

该程序是针对欧拉计划问题“ 3和5的倍数”而制作的。尽管这确实解决了问题,但我想进一步改进代码。具体来说,应使其输入的项目数不受限制,而不仅限于两个基数。

以某种方式,我想到了使用列表,使函数递归或在函数内使用函数。

def SumOfMultipleBase2(multiple1 , multiple2 , start , limit):
sum = 0
    for i in range(start , limit):
        if 1%multiple1 == 0 or 1%multiple2==0:
           sum += 1
print('The sum of the multiples of ' , multiple1, ' or' , multiple2 , 'between ', start , ' to ' , limit , ' is ' , sum , '.')

1 个答案:

答案 0 :(得分:1)

除非您想使用'* args'传递数字,否则我认为列表或元组都可以。然后,代码可能类似于:

implicit final class UserTags(x: TagsAndTags2.type)
{
    def dialog(caption: String): String = ???
}