Home > other >  How do I subtract a tuple from floats in a function? Gives error: TypeError: unsupported operand typ
How do I subtract a tuple from floats in a function? Gives error: TypeError: unsupported operand typ

Time:02-19

I have a quick question. I want to get three answers when I return the Power function since I have three numbers in my tuple t2. But it gives me this error I can't do anything with. Pls help.

t1 = 25.0
t2 = 228.66, 235.6763, 248.161
speed = 100.16
width = 943.0 
thickness = 0.26

def Power(t2, t1):
    "Test123"
    Power = (t2-t1)*speed*width*thickness*6*10**-5
    return Power

print(Power(t2, t1))

CodePudding user response:

This should do it:

t1 = 25.0
t2 = 228.66, 235.6763, 248.161
speed = 100.16
width = 943.0 
thickness = 0.26

def Power(t2, t1):
    return tuple((tx-t1)*speed*width*thickness*6*10**-5 for tx in t2)
 

print(Power(t2, t1))

Output:

(300.07951304448, 310.4175661102464, 328.8129441742081)

CodePudding user response:

One way you can do it is by using a numpy array instead of a tuple.

import numpy as np

t1 = 25.0, 25.0, 25.0
t2 = np.array([228.66, 235.6763, 248.161])
speed = 100.16
width = 943.0 
thickness = 0.26

def Power(t2, t1):
    Power = (t2-t1)*speed*width*thickness*6*10**-5
    return Power

print(Power(t2, t1))
  • Related