Home > Enterprise >  how can i use the output of one function to another function?
how can i use the output of one function to another function?

Time:05-01

Let's assume I have two functions

def seq():
    #here I wrote a code that evaluates the mean of a value from a csv file
    print(x)#assuming the condition in the above code is true it prints x
seq()

and

def lenn():
    p=4
    d=#I want this variable to be the value that the 1st function produces
    x=d/p
lenn()

One produces an integer and the other uses the output of the 1st function and then divides it with an integer to produce its own output. How do I call the function? I tried calling the function name but when I tried to divide the function name with an integer it keeps saying that I have a None type. I also tried to put the 1st first function inside the 2nd function but I had the same problem.

How can i solve this?

CodePudding user response:

Don't use print but return (print has no return value, so this defaults to None):

def seq():
    return int(input())

def lenn():
    p=4
    d=seq()
    x=d/p
    return x

print(lenn())

CodePudding user response:

The problem is that seq does not return the inputted value (x). Anyway, I wouldn't place int(input(x)) in its own function. You can try something like

def lenn():
    p=4
    d=int(input())
    x=d/p
    return x
  • Related