Define Floating-Point Literals (Solution)
As before, I have IDLE’s interactive shell open on the left and a placeholder file for the exercise solution on the right. It already has the instructions defined as a multiline Python string at the top. Once again, we’re going to define a variable, so we start typing the name of the variable, which is
num, followed by the assignment operator (
=) and the floating-point literal.
00:24 The value of that variable should be 175 thousand, but if I write it like this, Python would create an integer instead of a floating-point number. To fix that, I can just append the decimal point and a zero. This is great.
We’ve assigned the expected numeric value to the variable, but they’re specifically asking us to use E notation in the floating-point literal. With E notation, Python takes the number to the left of the
e and multiplies it by 10 raised to the power of the number after the
e. For example, 0.001 times 10 to the power of 3, or 1000, will move the decimal point 3 places to the right.
Become a Member to join the conversation.