Python can be used as a powerful calculator to perform various mathematical calculations. Here are some examples:
x = 5 y = 10 result = x + y print(result) # Output: 15
x = 15 y = 7 result = x - y print(result) # Output: 8
x = 3 y = 4 result = x * y print(result) # Output: 12
x = 10 y = 2 result = x / y print(result) # Output: 5.0
x = 2 y = 3 result = x ** y print(result) # Output: 8
Now, it's time to practice! Solve the following exercises:
Write a Python program to calculate the area of a rectangle. Ask the user to enter the length and width of the rectangle, then compute and display the area.
Write a Python program to convert a temperature from Celsius to Fahrenheit. Ask the user to enter a temperature in Celsius, then calculate and print the equivalent temperature in Fahrenheit. The formula for conversion is: Fahrenheit = (Celsius * 9/5) + 32.
Write a Python program to calculate the length of the hypotenuse of a right triangle. Ask the user to enter the lengths of the two other sides of the triangle (a and b), then calculate and display the length of the hypotenuse using the Pythagorean theorem: hypotenuse^2 = a^2 + b^2.
Note: To work on the exercises, create a Python script file (e.g., calculations.py) and write the code for each exercise in separate functions. Then call the functions to test your solutions.