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

Function to bring number below a certain number

I have a function in which i get 2 numbers and add 75 to it, i dont want the resultant number to exceed 275, is there a python function that can do this for me, the code is like below,

def newnumber(num1,num2):
    numbers = num1+num2+75    
    if numbers >275:
            numbers = numbers - 275;
    else:
            numbers 
    return numbers 

Above code just does it once, i want it sort of looped or if there is any python builtin function that can do this, it will be helpful

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

>Solution :

Did you mean to use a while loop?

def newnumber(num1, num2):
    numbers = num1 + num2 + 75    
    while numbers > 275:
        numbers -= 275
    return numbers 
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