Python Forum
HELP - Returning the first self number superior or equal to my argument - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: HELP - Returning the first self number superior or equal to my argument (/thread-13813.html)



HELP - Returning the first self number superior or equal to my argument - Kokuzuma - Nov-01-2018

Hello,

I am a student and a beginner in learning python coding, and I'm stuck on a self-numbers exercise, where I'm asked to return, from the NextAuto(n) function, the first self-number superior or equal to n with n belonging to N*.

But I don't really know how to do it, I tried something but it doesn't work :

def NextAuto(n) :
    atnb=[]
    x=0
    x>=n
    while x :
        atnb.append(x)
        for x in atnb :
            sommex=0
            for s in (list(int(c) for c in str(x))) :
                sommex+=s
        if  n==(x+sommex) in atnb :
                atnb.remove(n)
    return(atnb[0]) 
Could you please help me by showing me an example about returning the first special item superior or equal to an argument, with even numbers for example, or simply by showing me clues on this specific case to find the answer ?

Thank you in advance.


RE: HELP - Returning the first self number superior or equal to my argument - ichabod801 - Nov-01-2018

x >= n doesn't really do anything. You want x = n + 1. Then you should check x against the function you wrote in your first post. If it returns True, you return that number. Otherwise you increase x by 1 and continue through the loop. Everything but the initial setting of x would be in the while loop, which could just be a while True: loop.