Bird
0
0
Raspberry Piprogramming~10 mins

Displaying text on OLED in Raspberry Pi - Interactive Code Practice

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

Complete the code to initialize the OLED display.

Raspberry Pi
import Adafruit_SSD1306

# Create display instance
[1] = Adafruit_SSD1306.SSD1306_128_64(rst=None)
Drag options to blanks, or click blank then click option'
Adisplay
Bdevice
Cscreen
Doled
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name unrelated to the display like 'device' or 'screen'.
Forgetting to assign the display instance to a variable.
2fill in blank
medium

Complete the code to clear the OLED display before writing text.

Raspberry Pi
oled.[1]()
Drag options to blanks, or click blank then click option'
Aclear
Bbegin
Creset
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using show() instead of clear().
Using begin() which initializes but does not clear.
3fill in blank
hard

Fix the error in the code to display text on the OLED.

Raspberry Pi
from PIL import Image, ImageDraw, ImageFont

image = Image.new('1', (oled.width, oled.height))
draw = ImageDraw.Draw(image)
draw.text((0, 0), 'Hello, OLED!', font=[1], fill=255)

oled.image(image)
oled.show()
Drag options to blanks, or click blank then click option'
AImageFont.load()
BImageFont.default()
CImageFont.load_default()
DImageFont.font_default()
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like default() or font_default().
Forgetting the parentheses after the method.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths if length is greater than 3.

Raspberry Pi
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Clen(word) < 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the wrong comparison operator in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values greater than 10.

Raspberry Pi
data = {'a': 5, 'b': 15, 'c': 20}
result = {{ [1]: [2] for k, v in data.items() if v [3] 10 }}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original key instead of uppercase.
Using the wrong comparison operator like '<'.