
Python Project Example
Insurance fee Calculator
Instructions
A program to calculate the driving insurance is a good Python project example to show the possibilities of functions and conditionals. Your task is to write a Python program that calculates the insurance fee based on the user input. The program will request the user to enter the following data:
– His/her age
– The year when his/her license was issued
– The type of car the policy will cover: suv, sedan, sportscar, hatchback
The final fee will be displayed according to the following conditions:
- If the age of the driver is less than 19: Return (“Request rejected”). The policy does not cover drivers with no experience.
- If the driver is older than 19 and younger than 25 and his/her driver license is greater than 1 year and less than 4 years and the car type is a sedan, sportscar or hatchback:
Return “Only third party insurance allowed and 30% premium on regular fee”. - If the driver is older than 25 years and the car is a sedan or a sportscar: Return “5% premium on regular fee”.
- If the driver is older than 30 and has a valid license for at least 7 years: Return “25% discount on regular fee”.
- Any other situation: Return “Regular fee”.
The goal of this Python project is to practice core concepts such as functions and conditional statements. It is also an example of functional programming, a programming paradigm that emphasizes the use of pure functions, immutability, and higher-order functions.
It is very common in Python because it offers several benefits. First, it promotes code reusability and modularity, making it easier to test and maintain code. Second, functional programming encourages the use of immutable data structures, which reduces the risk of unexpected side effects and makes programs more predictable. Third, it enables parallel and concurrent programming, as pure functions can be executed independently without interfering with each other. Finally, functional programming aligns well with Python’s philosophy of simplicity and readability, allowing developers to write concise and expressive code.
Python Project solved
This program defines a function "calculate_insurance_fee()" that prompts the user to enter their age, license year, and car type. It then uses conditional statements to determine the appropriate insurance fee based on the given conditions. The program prints the result according to the specified conditions.
Please note that the program assumes the current year is 2023 for calculating the license year.