Home > database >  How to set a value to function in python
How to set a value to function in python

Time:10-09

I new at python programming and I am on a project about math, and in a moment I have faced a problem I need to do some operations about two values ​​inside the function and according to their sizes or etc. there will be a output of this function. This is what i'm trying to do:

def my_func(x,y):
  if x > y:
    my_func() = x**y   y**x
  else:
   my_func() = y*x

and i will use this in an if statement.

if my_func(x,y) and my_func(x,z) == True:

  #do something

i know it will not work cuz this is not the way the functions work. But if there is a way to do this i would be pleased to know. If this question looks a little bit weird, sorry i don't know very much about python programming but i'm trying to improve myself.

CodePudding user response:

is this what you want to do ??

def my_func(x,y):
   if x > y:
       return x**y   y**x
   else:
       return  y*x

result = my_func(4,5)

CodePudding user response:

You have to return the ouput from the function when you have performed the necessary actions according to your inputs parameters. You can do it like below.

 def my_func(x, y):
    if x > y:
        output = x ** y   y ** x
    else:
        output = y * x
    return output


print(my_func(2, 3))
print(my_func(3, 2))
  • Related