1. Programming Exercise #3 (How Much Insurance) The program should consist of a
ID: 3864996 • Letter: 1
Question
1. Programming Exercise #3 (How Much Insurance) The program should consist of a main function, which asks the user to enter the replacement cost of a building, a function called compute_insurance that calculates and displays the minimum amount of insurance that is needed.
a. Name your Python file Your initials + Insurance.py
b. The program should use global constants for the insurance rate
c. The main function should call the compute_insurance function with building replacement cost as an argument.
d. Money amounts should be formatted as currency.
e. All output should be displayed with descriptive text, such as, “Amount of insurance is $XXX.XX
Explanation / Answer
Python 2.7 code:
def func(c):
global insurance_rate
print "The minimum amount of insurance that is needed = $", (c*insurance_rate/100)
insurance_rate = 30; # 30 percent
if __name__ == '__main__':
print "Enter the replacement cost of a building in dollars"
cost = float(raw_input().strip())
insurance_cost = func(cost);
Sample Output:
Enter the replacement cost of a building in dollars
100000
The minimum amount of insurance that is needed = $ 30000.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.