Home > Software engineering >  Transfer result of a function to another. Python
Transfer result of a function to another. Python

Time:11-28

I have get_Time function working fine but I would like to take the result it produces and store it int the "t" variable inside the function simple_Interest function. Here is the code I have now.

y = input("Enter value for year: ")
m = input("Enter value for month: ")
p = input("Enter value for principle: ")
r = input("Enter value for rate (in %): ")

def get_Time(y, m, d):
   total_time = y   m / 12   d / 365
   return total_time
print ("The total time in years is: " , get_Time(int(y), int(m), int(d)))

def simple_Interest(t, p, r):
  simplint = p *(r / 100) * t
return simplint

sorry if I sound like a dummy.. im still very newbish to python and programming in general but im learning. thanks in advance for your help.

CodePudding user response:

since they are both functions you can one inside the other one like fallowing

def get_Time(y, m, d):
   total_time = y   m / 12   d / 365
   return total_time
print ("The total time in years is: " , get_Time(int(y), int(m), int(d)))

def simple_Interest(p, r):
  simplint = p *(r / 100) * get_Time(y, m ,d) #  maybe you can make the variables global or pass them to the simple_Insterst
return simplint

CodePudding user response:

You can do it:

y = input("Enter value for year: ")
m = input("Enter value for month: ")
p = input("Enter value for principle: ")
r = input("Enter value for rate (in %): ")

def get_Time(y, m, d):
    total_time = y   m / 12   d / 365
    return total_time

t = get_Time(int(y), int(m), int(d))
print ("The total time in years is: " , t)

def simple_Interest(t, p, r):
    simplint = p *(r / 100) * t
    return simplint

Then you can call simple_Interest function.

simple_Interest(t, p, r)
  • Related