In: Computer Science
Into to Python
Instructions: • In this lab you are to debug the code found at the end of these instructions: Find and correct all problems found in the code. Create comments in the code explaining what you found and how you corrected it • The purpose of this program is to calculate car insurance rates using the following rules: The base rate of insurance is $50 a month, Males pay a 25% premium over the base rate, Drivers in Michigan and Florida pay a 10% premium over the base rate, and Individuals under the age of 21 or over the 70 pay a 5% premium over the base rate
Grading: 2 – General, compiles, comments, proper indentation, etc 4
– Problem 1 found and corrected 4
– Problem 2 found and corrected 4
– Problem 3 found and corrected 4
– Problem 4 found and corrected
Source Code:
# Lab 3.2 #
BASE_RATE = 50
print('Car Insurance Rate Estimator/n')
age = int(input('Enter your current age: '))
sex = input('Enter your sex: ')
state = input('Enter your state of residence: ')
cost = BASE_RATE
if(sex = 'M'):
cost = BASE_RATE + (BASE_RATE * .25)
if(state == 'MI' or state == 'FL'):
cost = BASE_RATE + (BASE_RATE * .25)
if(age < 21 or age > 70):
cost = BASE_RATE + (BASE_RATE * .25)
print('\nYou are a', age, 'year old ' + sex, 'and you live in ' + stateOfResidence)
print('Your insurance will cost $', format(cost, '.2f'), sep='')
#---------------------------------------
BASE_RATE = 50
print('Car Insurance Rate Estimator/n')
age = int(input('Enter your current age: '))
sex = input('Enter your sex: ')
state = input('Enter your state of residence: ')
cost = BASE_RATE
# assignment operator was used instead of comparison
if (sex == 'M'):
cost = BASE_RATE + (BASE_RATE * .25)
if (state == 'MI' or state == 'FL'):
#corrected the fraction and the formula
cost = cost + (BASE_RATE * .1)
if (age < 21 or age > 70):
#corrected the fraction and the formula
cost = cost + (BASE_RATE * .05)
#wrong variable name used, corrected it
print('\nYou are a', age, 'year old ' + sex, 'and you live in ' + state)
print('Your insurance will cost $', format(cost, '.2f'), sep='')
#-----------------------------------------------