#solution to problem 3 from the programming problems after chapter #3 on page 114 #In this program we will use TOP-DOWN design #we will write function insurance that has 2 formal parameters #cost and ins_rate. #Function calculates #the cost of insurance based on replacement cost and insurance rate #which is 80% in this program #in main, we will calculate the insurance cost for 3 different people #we will also introduce a new concept: GLOBAL CONSTANT #rules: #1. use ALL CAPITAL LETTERS in the global constant name #2. declaer global constant BEFORE ALL FUNCTION DEFINITIONS #GLOBAL CONSTANT WILL BE AVAILABLE FOR USE IN ALL FUNCTIONS #In this program we have one constant value - 80% insurance rate RATE = 0.8 def insurance(cost, ins_rate): #we will declare local variable res to hold the result #local variable res will be only availaible for use #in this specific function res = cost * ins_rate print(res) def main(): #calculate insurance cost for 3 different people #input cost1=int(input("enter first replacement cost ")) cost2=int(input("enter second replacement cost ")) cost3=int(input("enter third replacement cost ")) #calling the function and printing results print("the insurance amount for first property is") insurance(cost1, RATE) print("the insurance amount for second property is") insurance(cost2, RATE) print("the insurance amount for third property is") insurance(cost3, RATE) #the function insurance was called 3 times #actual parameters #first call: cost1, RATE #second call: cost2, RATE #third call: cost3, RATE main()