0
0
Pythonprogramming~10 mins

Variable assignment 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 the value 10 to the variable x.

Python
x = [1]
Drag options to blanks, or click blank then click option'
Ax
B'10'
C10
Dten
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the number, which makes it a string.
Using the variable name instead of a value.
2fill in blank
medium

Complete the code to assign the string 'hello' to the variable greeting.

Python
greeting = [1]
Drag options to blanks, or click blank then click option'
A'hello'
Bhello
C"hello"
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the string.
Using the variable name instead of a string value.
3fill in blank
hard

Fix the error in the code to assign the sum of 5 and 3 to the variable total.

Python
total = 5 [1] 3
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Leaving out the operator.
4fill in blank
hard

Fill both blanks to assign the length of the word 'apple' to the variable length.

Python
length = [1]([2])
Drag options to blanks, or click blank then click option'
Alen
Bword
C'apple'
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined.
Not using the length function.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as uppercase letters of words and values as their lengths, only for words longer than 3 letters.

Python
result = [1]: [2] for word in words if len(word) [3] 3}
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as key without uppercase.
Using wrong comparison operators.
Mixing keys and values.