0
0
Pythonprogramming~15 mins

abs() and round() in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Using abs() and round() in Python
๐Ÿ“– Scenario: You are working on a simple weather app that shows temperature differences and rounded temperatures for easy reading.
๐ŸŽฏ Goal: Build a small program that calculates the absolute difference between two temperatures and rounds a temperature value to the nearest whole number.
๐Ÿ“‹ What You'll Learn
Create variables with exact temperature values
Use the abs() function to find the absolute difference
Use the round() function to round a temperature
Print the results exactly as instructed
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Weather apps often show temperature differences and rounded temperatures to help users understand the weather easily.
๐Ÿ’ผ Career
Knowing how to use abs() and round() is useful in data processing, financial calculations, and any job involving numbers.
Progress0 / 4 steps
1
Create temperature variables
Create two variables called temp_morning and temp_evening with the values -3.7 and 5.2 respectively.
Python
Need a hint?

Use the assignment operator = to set the values.

2
Calculate absolute temperature difference
Create a variable called temp_diff and set it to the absolute difference between temp_evening and temp_morning using the abs() function.
Python
Need a hint?

Use abs() around the subtraction to get a positive result.

3
Round the morning temperature
Create a variable called rounded_morning and set it to the value of temp_morning rounded to the nearest whole number using the round() function.
Python
Need a hint?

Use round() with the variable inside the parentheses.

4
Print the results
Print the values of temp_diff and rounded_morning exactly as shown below, each on its own line:
Absolute difference: 8.9
Rounded morning temperature: -4
Python
Need a hint?

Use print() with f-strings to show the variable values.