0
Python type-conversion float
In the basic concept tutorial it says : >>> float(input("Enter a number: ")) + float(input("Enter another number: ")) Enter a number: 40 Enter another number: 2 42.0 When I clicked Try it yourself, it's: print(float(input("Enter a number: ")) + float(input("Enter another number: "))) What does it mean? I cannot run it even though I put input or copied what is in the tutorial? Can someone help me? and explain to me the method? Thank you very much!!!
1 Resposta
+ 9
The reason is because the tutorials take example from entering commands into the Python Shell, while in Code Playground, we are expected to write scripts and run them instead.
print(float(input("Enter a number: ")) + float(input("Enter another number: ")))
should work just fine in Code Playground. The difference between this and the above example you provided in the tutorials is that we need to print the text after the program has done computing the sum of the two numbers. In the Python Shell, no print function is needed because the shell would automatically provide output.
If you want to grasp what is going on, I suggest installing Python on a desktop/laptop.