Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 207

How can i solve a problem by using the outcome of a function as a variable in the following?

$
0
0

I have come up with this code:

lista= [5,3.2, 'Error', 44, 'Error', 35]listb= [70, 70, 20, 410,'Error', 4.9]for i in range(6):    a= lista[i]    b= listb[i]    if a == 'Error' or b == 'Error':        print(f" Case {i}")        print(" One of the values is not a number")        print("-----")    else:        def c(a):                  c=0.1*a**3 -0.6*a**2             return c            def d(a,b,c):                       return a+b+c(a)        print(f" Case {i} ")        print(f" Initial values {a} {b}")        print(f" Final values {c(a)} {d(a,b,c)}")        print("-----")``

The problem is the second function, which doesn't work. If i erase everything with d and function number two, it's exactly the same as the desired output.The error i get is: supported operand type(s) for +: 'int' and 'function'Can somebody please help me?The desired output:

Case 0Initial values 5 70Final values -2.5 72.5

Case 1Initial values 3.2 70Final values -2.8672 70.3328

Case 2One of the values is not a number

Case 3Initial values 44 410Final values 7356.799999999999 7810.799999999999

Case 4One of the values is not a numberCase 5Initial values 35.0 4.9Final values 3552.5 3592.4

The number of active lines can't be more than 20.


Viewing all articles
Browse latest Browse all 207

Trending Articles