Python Forum
Calculate the multiple of a number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate the multiple of a number
#1
Hello,

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Les nombre multiples de n compris entre 1 et 60
def multiple(n):
    for i in range(1,61):
        r=i//n
        if i%n==0:
            print(i,r)
    return(r)
print(multiple(15))
The output of the script is like this :
./multiple_nombre_v3.py
(15, 1)
(30, 2)
(45, 3)
(60, 4)
4

My script is giving the multiple of a number (here 15 for example) and the script is working.
I want to optimize it. I have these two lines print(i,r) and return(r ). Is there a way I can get rid of one of these two lines and yet have the correct output giving only the multiple of a number ? I am asking this because the return(r ) sends "4" and in the 'if condition' I did not find an another way besides "print(i,r)" to show the multiples of a number.
Reply


Messages In This Thread
Calculate the multiple of a number - by pythonuser1 - Mar-24-2020, 10:30 PM
RE: Calculate the multiple of a number - by Fre3k - Mar-25-2020, 10:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  calculate the 10001st prime number topologh 7 6,519 Oct-05-2020, 07:41 PM
Last Post: deanhystad
  Divide a number - Multiple levels - Sum of all numbers equal to input number pythoneer 17 9,267 Apr-20-2018, 04:07 AM
Last Post: pythoneer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020