+ 1
what is wrong with this code?
x = print(float(input("Enter a number))) + (float(input("Enter another number))) if x == 50: print ("ok") else: print ("not ok") when i am entering the numbers 20 and 30 the answer is 50 and shoud print ok but it prints not ok why ?????? and why i can get output if i remove print?
12 Answers
+ 2
Remove the print function outside the input. You can't assign a print method to anything since it outputs a value and does not return one. Food for thought...
+ 1
Because you add result of print function with result of float function.when you move print you adding what actualy want at first place.if you have some doubts.put results of first adder in some variable and print it.and put result of second variable and print it.tjen you will see why you do not get 50.have a nice day;-)
+ 1
yes;-)
+ 1
I mean it should be
x = float (input("enter number"))+float (input ("enter number"))
When I say it does not return a value, I mean the print function. To return a value is to pass a value back to where the method was called from. Print does not do this and only outputs the value inside its parameters. That's why you cannot assign the print function to a variable because the print function does not return a value, meaning the variable is assigned to no value.
0
because the declared data type is float and the constanta in the statement is int. consider using int or change the value in the statement.
0
@vetarikisa, i am a beginner in any comp. language, so can you please give me example of what you mean by adding variable to the first and second result
0
@Gershon Fosu, do you mean by removing the the print function outside the input is to be
print (x = float(input("Enter a number))) + (float(input("Enter another number))
is that is you mean ???? and what do you mean by does not return one ??
0
a = print(float(input()))
print(a)
b = float(input())
print(b)
x = a + b
print(x)
0
@vetarikisa, thanks alot i understand now when i added print before the float it becomes no more float and itis noneType and the number in it no more number ,is that true?
0
@vetarikisa, thanks alot ;)
0
@Gershon Fosu, thanks alot :)
0
Your welcome