finding multiples of a number in Python

后端 未结 7 1140
甜味超标
甜味超标 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:26

    Does this do what you want?

    print range(0, (m+1)*n, n)[1:]
    

    For m=5, n=20

    [20, 40, 60, 80, 100]
    

    Or better yet,

    >>> print range(n, (m+1)*n, n)
    [20, 40, 60, 80, 100] 
    

    For Python3+

    >>> print(list(range(n, (m+1)*n, n)))
    [20, 40, 60, 80, 100] 
    

提交回复
热议问题