0
0
Pythonprogramming~10 mins

Why object-oriented programming is used in Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a class named Car.

Python
class [1]:
    pass
Drag options to blanks, or click blank then click option'
ACar
Bcar
Cvehicle
DCarClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase names for classes
Using unrelated names
2fill in blank
medium

Complete the code to add an __init__ method that stores the car's brand.

Python
class Car:
    def __init__(self, brand):
        self.[1] = brand
Drag options to blanks, or click blank then click option'
Acar_brand
Bname
Cbrand
Dbrand_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using different attribute names than parameters
Forgetting self.
3fill in blank
hard

Fix the error in the method to return the car's brand.

Python
class Car:
    def __init__(self, brand):
        self.brand = brand
    def get_brand(self):
        return self.[1]
Drag options to blanks, or click blank then click option'
Abrand_name
Bname
Ccar_brand
Dbrand
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a wrong attribute name
Missing self.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps car brands to their lengths.

Python
brands = ['Ford', 'BMW', 'Audi']
lengths = {brand[1]: len(brand) for brand in brands if len(brand) [2] 3}
Drag options to blanks, or click blank then click option'
A.upper()
B>
C<
D.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators
Not applying string methods correctly
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase brand names to their lengths if length is greater than 3.

Python
brands = ['Ford', 'BMW', 'Audi']
lengths = {{ [1]: [2] for brand in brands if len(brand) [3] 3 }}
Drag options to blanks, or click blank then click option'
Abrand.upper()
Blen(brand)
C>
Dbrand.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keys and values
Wrong comparison operator