Company insures Drivers Program in Python


A company insures its drivers in the following cases:

  1. If the driver is married.
  2. If the driver is unmarried, male & above 30 years of age.
  3. If the driver is unmarried, female & above 25 years of age.

This program is a simple example of using the if-elif-else statement in Python. The program takes input from the user for the age, sex, and marital status of a driver. It then uses this input to check if the driver should be insured or not. If the marital status is 'M' or 'm' (married), the program will print "Driver should be Insured".

If the marital status is 'U' or 'u' (unmarried) and the sex is 'M' or 'm' (male) and the age is greater than 30, the program will print "Driver should be Insured". If the marital status is 'U' or 'u' (unmarried) and the sex is 'F' or 'f' (female) and the age is greater than 25, the program will print "Driver should be Insured". If none of these conditions are met, the program will print "Driver should not be Insured".


Source Code

age = int(input("Enter the Age :"))
sex = input("Enter the Gender M/F :")
status = input("Enter the Marital Status U/M :")
if( status == 'M' or status == 'm'):
	print( "Driver should be Insured" )
elif( status == 'U' and sex == 'M' and age > 30 or status == 'u' and sex == 'm' and age > 30 ):
	print( "Driver should be Insured" )
elif( status == 'U' and sex == 'F' and age > 25 or status == 'u' and sex == 'f' and age > 25 ):
	print( "Driver should be Insured" )
else:
	print( "Driver should not be Insured" )
"""
age = int(input("Enter the Age :"))
sex = input("Enter the Gender M/F :")
status = input("Enter the Marital Status U/M :")
if ( ( status == 'M') or ( status == 'U' and sex == 'M' and age > 30 ) or( status == 'U' and sex == 'F' and age > 25 ) ):
	print( "Driver should be Insured" )
else:
	print( "Driver should not be Insured" )
 
"""

Output

Enter the Age :21
Enter the Gender M/F :F
Enter the Marital Status U/M :U
Driver should not be Insured

Example Programs