简体   繁体   中英

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

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))

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM