0
0
Intro to Computingfundamentals~10 mins

Debugging mindset in Intro to Computing - Interactive Code Practice

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

Complete the code to print the error message when an exception occurs.

Intro to Computing
try:
    result = 10 / 0
except ZeroDivisionError as [1]:
    print([1])
Drag options to blanks, or click blank then click option'
Ae
Berror
Cexception
Derr
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not matching the print statement.
Forgetting to use 'as' keyword.
2fill in blank
medium

Complete the code to check if a number is positive and print a message.

Intro to Computing
number = -5
if number [1] 0:
    print("Positive number")
else:
    print("Not positive")
Drag options to blanks, or click blank then click option'
A>=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causing wrong output.
Using '==' which only checks equality.
3fill in blank
hard

Fix the error in the code to correctly access the first element of the list.

Intro to Computing
my_list = [10, 20, 30]
first_element = my_list[1]
Drag options to blanks, or click blank then click option'
A(0)
B[0]
C{0}
D<0>
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses which call a function.
Using curly braces which define sets or dictionaries.
4fill in blank
hard

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

Intro to Computing
{word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Comparing the word string directly to a number.
5fill in blank
hard

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

Intro to Computing
{ [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 2
Dword.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.lower() instead of uppercase.
Not filtering words by length correctly.