-2
I’m making this simple unit converter.
I need him to do:
- Calculation of average speed in
Km/h
; - Print this result.
Then, in another function, I need to convert it to m/s
and print the result again.
But I keep getting the following error in the Output of the code snippet that I attached below:
"can’t Multiply Sequence by non-int of type 'float'"
dist_k1= 169.0
time_h1= 0.6
dist_k2= 169.0
time_h2= 1.0
dist_k3= 300.0
time_h3= 1.5
def get_deltaV(dist_k, time_h):
DeltaV = dist_k/time_h
return DeltaV,"Km/h"
DeltaV1= get_deltaV(dist_k1, time_h1)
DeltaV2= get_deltaV(dist_k2,time_h2)
DeltaV3= get_deltaV(dist_k3,time_h3)
print(DeltaV1)
print(DeltaV2)
print(DeltaV3)
def get_ms (DeltaV):
ms =DeltaV / 3.6
return (ms,"m/s")
ms1 = get_ms(DeltaV1)
ms2 = get_ms(DeltaV2)
ms3 = get_ms(DeltaV3)
print(ms1)
print(ms2)
print(ms3)
Why is this error occurring? How can I fix it?
get_deltaV
returns a tuple and this return you are passing as parameter toget_ms
, where the value is multiplied by 3.6. It should not beget_ms(DeltaV1[0])
?– Woss
It worked, thank you
– Marcello Fabrizio
But what would be the reason for that?
– Marcello Fabrizio
Of what? Of the error? What would be the expected result for the operation
(10, 'km/h') / 3.6
?– Woss
would then why are you sharing a tuple?
– Marcello Fabrizio
Exactly, as I commented initially when multiplication was still.
– Woss