0
0
Pythonprogramming~10 mins

Dynamic typing 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 assign a string to the variable.

Python
message = [1]
Drag options to blanks, or click blank then click option'
A"Hello, world!"
B100
CTrue
D3.14
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the string.
Using a number instead of a string.
2fill in blank
medium

Complete the code to change the variable type from int to float.

Python
number = 10
number = [1](number)
Drag options to blanks, or click blank then click option'
Alist
Bstr
Cfloat
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using str() which converts to text, not a number.
Using bool() which converts to True or False.
3fill in blank
hard

Fix the error by completing the code to add a number to a string correctly.

Python
age = 30
message = "I am " + [1] + " years old."
Drag options to blanks, or click blank then click option'
Afloat(age)
Bage
Cint(age)
Dstr(age)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to add an integer directly to a string causes an error.
Using int() or float() does not convert to string.
4fill in blank
hard

Fill both blanks to create a list of squares for numbers greater than 3.

Python
squares = [x[1]2 for x in range(1, 6) if x [2] 3]
Drag options to blanks, or click blank then click option'
A**
B>
C<
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of power operator.
Using < instead of > for filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

Python
result = {{ [1] }}: [2] for [3], v in data.items() if v > 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names like item.
Not converting keys to uppercase.