My first function returns (a, b). The second function must control it if (a, b) are True or False. If it is False call again the first function until the user put in right numbers.
It dose not work. Is it a good idea to do that in this way or not?

def lasin ():
    a=int( input ("Put in a 1<digit<53\n"))
    b=int( input ("put in a 1<digit<53\n"))  
    return a,b

def kontroll(a,b):
    while True:
        try:
             if a>1 and a<53:   
                break
             elif b>1 and b<53:
                break
        except NameError:
            print "Try again"
            lasin()

Thank alot for help and tips!

Don't you want to say something like a,b = lasin() instead of just lasin() ?

You understand, of course, that the variables a and b inside function lasin() are local to that function call, and disappear completely and forever after the return. They bear no relation whatsoever to the a and b in kontroll().

In your code :
1. when a and b are outside ]1, 53[, you do nothing except looping while true (infinite loop) - look at indentation.
2. If 1<a<b, you don't control if b is allright. You immediately break the loop

def lasin ():
    a=int( input ("Put in a 1<digit<53\n"))
    b=int( input ("put in a 1<digit<53\n"))  
    return a,b

def kontroll(a,b):
    while True:
        try:
             if a>1 and a<53 and b>1 and b<53:   
                break
        except NameError:
            print "Try again"
        (a,b)=lasin()

Thanks a lot, I have tried but the exception part of program didn´t works. I changed my code and I expect if a user put a letter instead of a digit the exception part of program must take care of mistake, , and give him chance to do it again.

def lasin ():
    a=int( input ("Put in a 1<digit<53\n"))
    b=int( input ("put in a 1<digit<53\n"))
    return a,b
def kontroll(a,b):
    while True:
        try:
            if a>1 and a<53 and b>1 and b<53:
                break
            print "Try again"
            a,b =lasin()
        except NameError:
                    print "Put a digit not a letter"
        
a,b=lasin()
kontroll(a,b)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.