+ 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?

8th Jul 2016, 5:58 AM
Ahmed Kamal
Ahmed Kamal - avatar
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...
8th Jul 2016, 8:17 AM
Gershon Fosu
Gershon Fosu - avatar
+ 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;-)
8th Jul 2016, 7:13 AM
vetarikisa
+ 1
yes;-)
8th Jul 2016, 3:47 PM
vetarikisa
+ 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.
8th Jul 2016, 5:15 PM
Gershon Fosu
Gershon Fosu - avatar
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.
8th Jul 2016, 7:36 AM
Ahmad Fadhel
Ahmad Fadhel - avatar
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
8th Jul 2016, 11:03 AM
Ahmed Kamal
Ahmed Kamal - avatar
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 ??
8th Jul 2016, 2:48 PM
Ahmed Kamal
Ahmed Kamal - avatar
0
a = print(float(input())) print(a) b = float(input()) print(b) x = a + b print(x)
8th Jul 2016, 3:25 PM
vetarikisa
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?
8th Jul 2016, 3:46 PM
Ahmed Kamal
Ahmed Kamal - avatar
0
@vetarikisa, thanks alot ;)
8th Jul 2016, 3:49 PM
Ahmed Kamal
Ahmed Kamal - avatar
0
@Gershon Fosu, thanks alot :)
8th Jul 2016, 5:56 PM
Ahmed Kamal
Ahmed Kamal - avatar
0
Your welcome
8th Jul 2016, 6:09 PM
Gershon Fosu
Gershon Fosu - avatar