0
Why do this code always returns that the value of nx is 0.0?
n1=float(input("n1")) n2=float(input("n2")) r=n2-n1 nx=str(input("Nx: ")) nx=float() def aritmetica_n(nx): nx=nx*r return nx print("value from n "+str(nx) The function should multiply the value given (nx) and then print the result but it always print 0.0
7 Antworten
+ 4
Nope. It will just create an empty float object, aka 0.0. You could do nx = float(nx). But Taste 's approach is more elegant 👆
+ 3
Line 5
Shouldnt it be nx=float(nx) ?
+ 2
And why making a function without calling it?
+ 2
First you define nx=str(input("Nx: ")). Then you redefine it as nx=float(). So whatever was entered before will be lost and nx will be overridden with 0.0 (the standard value of float()).
As already pointed out, the function aritmetica_n(nx) is never called so it won't do anything. Why are the lines nx=float() etc. indented?
+ 1
Thanks!!
0
Sorry there is a last line of code:
print(aritmetica_n(nx))
0
Won't nx=float() transform nx into float??