0
0
Pythonprogramming~10 mins

Adding custom attributes in Python - Interactive Code Practice

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

Complete the code to add a custom attribute color to the object car.

Python
class Car:
    pass

car = Car()
car.[1] = 'red'
print(car.color)
Drag options to blanks, or click blank then click option'
Aspeed
Byear
Ccolor
Dmodel
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong attribute name that doesn't match the print statement.
Trying to add attribute inside the class without defining __init__.
2fill in blank
medium

Complete the code to add a custom attribute age with value 5 to the object dog.

Python
class Dog:
    pass

dog = Dog()
dog.[1] = 5
print(dog.age)
Drag options to blanks, or click blank then click option'
Aage
Bweight
Cbreed
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the value to a wrong attribute name.
Forgetting to use dot notation.
3fill in blank
hard

Fix the error in the code to add a custom attribute height with value 180 to the object person.

Python
class Person:
    pass

person = Person()
person[1] = 180
print(person.height)
Drag options to blanks, or click blank then click option'
A:height
B[height]
C['height']
D.height
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of dot notation.
Missing the dot before the attribute name.
4fill in blank
hard

Fill both blanks to add a custom attribute speed with value 100 to the object bike.

Python
class Bike:
    pass

bike = Bike()
bike[1] = [2]
print(bike.speed)
Drag options to blanks, or click blank then click option'
A.speed
B100
C50
D.distance
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names or values.
Forgetting the dot before the attribute name.
5fill in blank
hard

Fill all three blanks to add a custom attribute name with value "Alice" to the object user.

Python
class User:
    pass

user = User()
user[1] = [2]
print(user.[3])
Drag options to blanks, or click blank then click option'
A.name
B"Alice"
Cname
D.username
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names or missing quotes around the string.
Mismatch between assigned attribute and printed attribute.