Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write a program to print the sum of 1 to n. While calculating sum omits the numbers which are multiples of x. Note :Use the concept of continue

Please help me with this I’m not able to omit number of multiple x

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Keywords such as for and continue shouldn’t be capitalized:

If you’re trying to find the sum of numbers that are not multiples of x then you can try this:

total = 0
n = int(input("Enter n: "))
x = int(input("Enter x: "))
for i in range(0,n+1): 
    if(i%x==0): 
        continue  
    total += i
print(total)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading