Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
144 lines (96 loc) · 2.75 KB
/
Copy pathmain.py
File metadata and controls
144 lines (96 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
Gather user info
Driver Name (string)
Driver Age (integer)
Coverage Level (string (SM, L, F))
Store this information in a dictionary
Driver Age
State Minimum
Liability Coverage
Full Coverage
16
2593
2957
6930
25
608
691
1745
35
552
627
1564
45
525
596
1469
55
494
560
1363
65+
515
585
1402
Abbreviated table taken from https://www.carinsurance.com/average-rates-by-age.aspxLinks to an external site.
Add the customer’s coverage cost to the dictionary according to their age and coverage desired using the table above
Ask the user if they've had any accidents
If the user has had any accidents, their coverage rate increases by 41%
Update the customer’s coverage cost in the dictionary
Ask the user if they want to pay up front for a 10% discount
If paying up front update the dictionary with the new rate
Output the annual insurance cost for the customer
"""
def get_coverage_cost(age, coverage):
"""
Returns the coverage cost based on age and coverage type.
Parameters:
- age (int): The age of the driver.
- coverage (str): The type of coverage ('SM', 'L', or 'F').
"""
rates = {
16: {'SM': 2593, 'L': 2957, 'F': 6930},
25: {'SM': 608, 'L': 691, 'F': 1745},
35: {'SM': 552, 'L': 627, 'F': 1564},
45: {'SM': 525, 'L': 596, 'F': 1469},
55: {'SM': 494, 'L': 560, 'F': 1363},
65: {'SM': 515, 'L': 585, 'F': 1402},
}
if age < 25:
return rates[16][coverage]
elif age < 35:
return rates[25][coverage]
elif age < 45:
return rates[35][coverage]
elif age < 55:
return rates[45][coverage]
elif age < 65:
return rates[55][coverage]
else:
return rates[65][coverage]
def main():
try:
driver_name = input("Enter Driver Name: ")
driver_age = int(input("Enter Driver Age: "))
coverage_level = input("Enter Coverage Level (SM, L, F): ").upper()
if coverage_level not in ['SM', 'L', 'F']:
raise ValueError("Invalid input.")
except ValueError as e:
print(f"Error: {e}")
return
insurance_cost = get_coverage_cost(driver_age, coverage_level)
customer_info = {
'Name': driver_name,
'Age': driver_age,
'Coverage Level': coverage_level,
'Coverage_cost': insurance_cost
}
accidents = input("Have you had any accidents? (yes/no): ").lower()
if accidents == 'yes':
customer_info['Coverage_cost'] *= 1.41
upfront = input("Do you want to pay upfront for a 10% discount? (yes/no): ").lower()
if upfront == 'yes':
customer_info['Coverage_cost'] *= 0.9
print(f"\nAnnual insurance cost for {customer_info['Name']} is ${customer_info['Coverage_cost']:.2f}")
if __name__ == "__main__":
main()