Python Division

DAILY PYTHON PUZZLE: Python Division

What is the output of this code snippet?

 

x = 55 / 11
print(x)

The majority of people solve this puzzle correctly. Even so, the first goal of this puzzle is to introduce the concept of variables. Python evaluates the result of the expression on the right side of the equation and stores it in the variable x. After defining the variable, you can access it at any point in the program code.

The second goal of this puzzle is to show an interesting twist in the code: Python division always returns a floating point number. Thus, variable x stores the float value 5.0. The print function outputs the result as a float and not as an integer value 5. This is the source of most errors in the code. People focus too much on what they mean (semantics) and too little on how they say it (syntax). But computers are not good yet at interpreting the meaning of people. We must talk to them in their language.


Are you a master coder?
Test your skills now!

Related Video

Solution

5.0

 

Leave a Comment