python - Why does this program print the message more than once? -


i'm new programming , made simple program determine if user inputted number or odd. made function checks if inputted number integer rather float.

the program executes correctly if user types number, message telling whether number odd or prints multiple times if user inputs multiple floats first. why happen?

def check_int(x,y):     if x != int(x):         print "the number not integer"         y()     else:         print "the number integer"  def even_odd():     given_number = input("please type integer: ")     check_int(given_number, even_odd)     if (given_number % 2) != 0:         print "the number odd"     elif (given_number % 2) == 0:         print "the number even"  even_odd()  

even_odd called within check_int again (under name y). that's why see output multiple times.

i suppose think required in order continue even_odd after check_int finished. not necessary. when function finished, program automatically continues function called.

simply remove y parameter check_int, remove line y() , change check_int(given_number, even_odd) check_int(given_number).


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -