Calculate the Absolute Value (Solution)
00:00
Okay. The first instruction is virtually identical to the one from the previous exercise, so this one should be fairly easy. You define a variable called num and assign a floating-point number obtained from the user. So, enter a number.
00:20
Now, you can print the message onto the screen using an f-string: f"The absolute value of {num} is {}"
00:29
and here inside the second pair of curly brackets, you can write abs(), which is short for absolute value, and you pass your number. Now, let’s save and reload it. Let’s enter -10, as in the example. Great.
00:46 You’re getting the intended result. You solved this exercise quickly. The next exercise may be a bit more challenging.
Become a Member to join the conversation.
