Skip to content
Foxipa
Code Completion 5 Challenges

Complete the Python annotations code

Practice annotated assignment syntax and the compatibility behavior of explicitly stringized annotations.

Intermediate ~8 min read

Challenge 1

Annotate count as an int and assign 5.

python Your answer
count
print(count)

Press Ctrl⌘Enter to check your answer

Challenge 2

Declare total with an int annotation without assigning a value in the declaration.

python Your answer
total
total = 12
print(total)

Press Ctrl⌘Enter to check your answer

Challenge 3

Annotate the class attribute name as a str and give it the value 'Ada'.

python Your answer
class Person:
    name

print(Person.name)

Press Ctrl⌘Enter to check your answer

Challenge 4

Add an int annotation to the local variable total while keeping its assigned value.

python Your answer
def calculate():
    total = 10
    return total

print(calculate())

Press Ctrl⌘Enter to check your answer

Challenge 5

Complete the parameter and return annotations with names that are intentionally not defined. The future import must preserve them as strings so the program can print the annotation dictionary.

python Your answer
from __future__ import annotations

def describe(value: 
    return value

print(describe.__annotations__)

Press Ctrl⌘Enter to check your answer