finding multiples of a number in Python

后端 未结 7 1033
甜味超标
甜味超标 2021-02-07 10:48

I\'m trying to write a code that lets me find the first few multiples of a number. This is one of my attempts:

def printMultiples(n, m):
for m in (n,m):
    prin         


        
7条回答
  •  再見小時候
    2021-02-07 11:03

    def multiples(n,m,starting_from=1,increment_by=1):
        """
        # Where n is the number 10 and m is the number 2 from your example. 
        # In case you want to print the multiples starting from some other number other than 1 then you could use the starting_from parameter
        # In case you want to print every 2nd multiple or every 3rd multiple you could change the increment_by 
        """
        print [ n*x for x in range(starting_from,m+1,increment_by) ] 
    

提交回复
热议问题