Complete the code to print the global variable count inside the function.
count = 10 def show_count(): print([1]) show_count()
The variable count is defined outside the function, so it is a global variable. To access it inside the function, just use its name count.
Complete the code to modify the global variable score inside the function.
score = 5 def increase_score(): global [1] score += 1 increase_score() print(score)
To change a global variable inside a function, you must declare it as global followed by its name. Here, the global variable is score.
Fix the error by completing the code to correctly print the global variable name inside the function.
name = "Alice" def greet(): print([1]) greet()
Name which is undefined.The variable name is global and should be used exactly as defined. Variable names are case-sensitive, so Name is different and undefined.
Fill both blanks to create a dictionary with word lengths only for words longer than 3 letters.
words = ["apple", "cat", "banana", "dog"] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) to get the length of each word. The condition len(word) > 3 filters words longer than 3 letters.
Fill all three blanks to create a dictionary with uppercase keys and values only for positive values.
data = {"a": 1, "b": -2, "c": 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
print(result)The dictionary comprehension uses k.upper() to make keys uppercase, keeps values v, and filters only positive values with v > 0.