Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update q7.py #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/q7.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,23 @@ def describe_car(self):
# Task 2
# Create an instance of the Car class with the following attributes and call describe_car method:
# - Make: Toyota, Model: Corolla, Year: 2020

class Car:
"""
Task 1
- Define a class named Car with attributes: make, model, year
- Initialize these attributes in the __init__ method
- Add a method named describe_car() that prints information about the car as "Year Make Model"
"""
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year

def describe_car(self):
# Print the car's information in the format "Year Make Model"
print(f"{self.year} {self.make} {self.model}")

# Task 2: Create an instance of the Car class and call describe_car method
car = Car("Toyota", "Corolla", 2020)
car.describe_car() # Output: "2020 Toyota Corolla"