0
0
Testing Fundamentalstesting~10 mins

Static analysis tools in Testing Fundamentals - 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 static analysis tool that checks code style.

Testing Fundamentals
def check_code_style(code):
    issues = []
    if not code.endswith([1]):
        issues.append("Code should end with a newline.")
    return issues
Drag options to blanks, or click blank then click option'
A"\n"
B"\t"
C";"
D" "
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tab or space instead of a newline character.
Forgetting to include quotes around the newline character.
2fill in blank
medium

Complete the code to detect unused variables in a simple code snippet.

Testing Fundamentals
def find_unused_vars(code_vars, used_vars):
    unused = [var for var in code_vars if var [1] used_vars]
    return unused
Drag options to blanks, or click blank then click option'
A==
Bin
Cnot in
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using in instead of not in, which would find used variables instead.
Using equality operators which don't check membership.
3fill in blank
hard

Fix the error in the code that checks for function naming conventions.

Testing Fundamentals
def is_valid_function_name(name):
    return name.[1]("_") and name.islower()
Drag options to blanks, or click blank then click option'
Astartswith
Bendswith
Ccontains
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using endswith which checks the end of the string.
Using contains which is not a valid string method.
4fill in blank
hard

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

Testing Fundamentals
lengths = {var: [1] for var in variables if len(var) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(var)
B>
C<
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name itself instead of its length.
Using less than < instead of greater than >.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase variable names to their values only if the value is positive.

Testing Fundamentals
result = [1]: [2] for [3], val in data.items() if val > 0
Drag options to blanks, or click blank then click option'
Avar.upper()
Bval
Cvar
Dkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using key instead of var as loop variable.
Not converting variable names to uppercase for keys.