Home > database >  How can I split this function into 2, so that it contains a main function?
How can I split this function into 2, so that it contains a main function?

Time:10-08

I coded a user defined max function (even though it's included in the python default). This function works, but I cannot figure out how to split this into 2 functions! My main function needs to include the x and y input variables. I've been trying to figure out parameter/argument passing for hours now and still cannot figure out how to pass variables properly.

x=input("Enter integer value 1...")
y=input("Enter integer value 2...")

def max(x,y):
     if x > y:
         return x
     elif y > x:
         return y 


 print(max(x,y))

CodePudding user response:

Just move the top-level code into the main() function.

def main():
    x=input("Enter integer value 1...")
    y=input("Enter integer value 2...")
    
    print(max(x, y))

if __name__ == "main":
    main()
  • Related