Python Forum
HELP - Returning the first self number superior or equal to my argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP - Returning the first self number superior or equal to my argument
#1
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.
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP - Returning self numbers lower or equal to my argument Kokuzuma 4 2,743 Nov-01-2018, 06:35 PM
Last Post: Kokuzuma
  Divide a number - Multiple levels - Sum of all numbers equal to input number pythoneer 17 8,858 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