0
0
Pythonprogramming~10 mins

Naming rules and conventions 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 define a valid variable name in Python.

Python
my[1] = 10
Drag options to blanks, or click blank then click option'
A1var
B_var
C-var
Dvar!
Attempts:
3 left
💡 Hint
Common Mistakes
Starting variable names with a digit
Using special characters in variable names
2fill in blank
medium

Complete the code to follow Python naming conventions for constants.

Python
[1] = 3.14
Drag options to blanks, or click blank then click option'
ApiValue
BPi_Value
Cpi_value
DPI_VALUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase letters for constants
Not using underscores to separate words
3fill in blank
hard

Fix the error in the variable name to make it valid.

Python
user[1]name = 'Alice'
Drag options to blanks, or click blank then click option'
A-name
B name
C_name
D1name
Attempts:
3 left
💡 Hint
Common Mistakes
Including spaces in variable names
Starting variable names with digits
Using hyphens in variable names
4fill in blank
hard

Fill both blanks to create a dictionary comprehension with valid variable names and a condition.

Python
{word: len(word) for word in words if len(word) [1] [2]
Drag options to blanks, or click blank then click option'
A>
B<
C3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid operators
Using variable names instead of numbers in conditions
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension with uppercase keys, values, and a condition.

Python
result = [1]: [2] for word in words if len(word) [3] 4
Drag options to blanks, or click blank then click option'
Aword.upper()
Bword
C>
Dlen(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using length as key instead of uppercase word
Using wrong comparison operator
Mixing keys and values