0% found this document useful (0 votes)
2 views2 pages

Class Car

The document defines a Car class with attributes for brand, model, color, engine, and price, along with a method to display car information. The main function creates a dictionary of car objects and prompts the user to input a letter to select a car, displaying its information if valid. If the input is invalid, it prompts the user to try again.

Uploaded by

afura369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Class Car

The document defines a Car class with attributes for brand, model, color, engine, and price, along with a method to display car information. The main function creates a dictionary of car objects and prompts the user to input a letter to select a car, displaying its information if valid. If the input is invalid, it prompts the user to try again.

Uploaded by

afura369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

class Car:

def __init__(self, brand, model, color, engine, price):

self.brand = brand

self.model = model

self.color = color

self.engine = engine

self.price = price

def display_info(self):

print("Brand:", self.brand)

print("Model:", self.model)

print("Color:", self.color)

print("Engine:", self.engine)

print("Price:", self.price)

def main():

cars = {

"M": Car("Mercedes", "S-Class", "Black", "V8", "$100,000"),

"T": Car("Toyota", "Corolla", "White", "Inline-4", "$20,000"),

"F": Car("Ford", "Mustang", "Red", "V6", "$30,000"),

"R": Car("Range Rover", "Evoque", "Blue", "V6", "$50,000")

user_input = input("Enter a letter (M for Mercedes, T for Toyota, F for Ford, R for Range Rover):
").upper()

if user_input in cars:

car = cars[user_input]

print("\nCar Information:")
car.display_info()

else:

print("Invalid input. Please try again.")

if __name__ == "__main__":

main()

You might also like