0
0
Pythonprogramming~10 mins

Method invocation flow 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 call the method greet on the object person.

Python
class Person:
    def greet(self):
        print("Hello!")

person = Person()
person.[1]()
Drag options to blanks, or click blank then click option'
Asay_hello
Bhello
Cgreet
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong method name that does not exist.
Forgetting the parentheses to call the method.
2fill in blank
medium

Complete the code to call the method add with argument 5 on the object calc.

Python
class Calculator:
    def add(self, x):
        return x + 10

calc = Calculator()
result = calc.[1](5)
print(result)
Drag options to blanks, or click blank then click option'
Asum
Bcalculate
Cplus
Dadd
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not exist.
Forgetting to pass the argument inside parentheses.
3fill in blank
hard

Fix the error by completing the code to call the method display on the object obj.

Python
class Display:
    def display(self):
        print("Showing content")

obj = Display()
obj[1]
Drag options to blanks, or click blank then click option'
A.display
B.display()
Cdisplay()
D->display()
Attempts:
3 left
💡 Hint
Common Mistakes
Missing the dot before the method name.
Missing the parentheses to call the method.
4fill in blank
hard

Fill both blanks to complete the method call that returns the length of the string stored in obj.text.

Python
class TextHolder:
    def __init__(self, text):
        self.text = text

obj = TextHolder("hello")
length = len(obj.text[1]()) if obj.text [2] "" else 0
print(length)
Drag options to blanks, or click blank then click option'
Astrip
B!=
C==
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators.
Using a method that does not exist on strings.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its uppercase form if the word length is greater than 3.

Python
words = ["apple", "cat", "banana", "dog"]
result = { [1]: [2] for [3] in words if len(word) > 3 }
print(result)
Drag options to blanks, or click blank then click option'
Aword
Bword.upper()
D{word}
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces around the key incorrectly.
Mixing up the key and value positions.
Using wrong variable names.