Exercise 4.5. (Pythons abs() function)
1. Ensure you have viewed the video (associated with this exercise) at this link >>
2. Implement the following specification using a Python program that incorporates a selection construct and the abs() function. Ensure that all variables have sensible names and make sure that your program uses the user friendly prompts and outputs as shown in the sample runtimes below.
Specification
The user is asked to enter the balance of a current account. If the balance is in credit they enter a positive number that represents the amount of money in the account. However, if the account is overdrawn they enter a negative number that represents the overdraft. Two examples of runtime expected are shown below (remember if there is no sign for the inputted number it is positive). Note for the purpose of this exercises ignore what happened if the user enters 0 (zero) for the balance.
Specification
The user is asked to enter the balance of a current account. If the balance is in credit they enter a positive number that represents the amount of money in the account. However, if the account is overdrawn they enter a negative number that represents the overdraft. Two examples of runtime expected are shown below (remember if there is no sign for the inputted number it is positive). Note for the purpose of this exercises ignore what happened if the user enters 0 (zero) for the balance.
3. Amend the program you developed for the exercise above (Exercise 4.5.2) so that it has the additional requirement of displaying the following when the user enters 0 (zero).
The account is neither overdrawn or in credit it has a zero balance.
Hint: elif
The account is neither overdrawn or in credit it has a zero balance.
Hint: elif
4. Implement the following specification using a Python program. Ensure that all variables have sensible names and make sure that your program has user friendly prompts and outputs.
Specification
A user is asks to enter temperature in degrees Celsius. Have the program display the temperature entered and the absolute temperature if it is below zero.
If the user enters 25 the program displays:
The temperature entered is 25 degrees Celsius
If the user enters -15 the program displays:
The temperature entered is -15 degrees Celsius which is 15 degree below zero.
Specification
A user is asks to enter temperature in degrees Celsius. Have the program display the temperature entered and the absolute temperature if it is below zero.
If the user enters 25 the program displays:
The temperature entered is 25 degrees Celsius
If the user enters -15 the program displays:
The temperature entered is -15 degrees Celsius which is 15 degree below zero.
END Next Exercise >>