Complete the code to print 'Hello, world!' in script mode.
print([1])
In Python, strings must be enclosed in quotes. Using quotes around 'Hello, world!' makes it a string literal that print() can output.
Complete the code to assign the number 5 to variable x in script mode.
x = [1]To assign a number, write the number without quotes. Quotes make it a string, which is different from a number.
Fix the error in the interactive mode code to correctly print the sum of 2 and 3.
print([1])
In interactive mode, you can write expressions like 2 + 3 directly to get the result 5. Using quotes prints the text, not the sum.
Fill both blanks to create a dictionary comprehension that includes only even numbers from 1 to 5.
evens = {x: x[1]2 for x in range(1, 6) if x [2] 2 == 0}The expression x**2 squares x. The condition x % 2 == 0 checks if x is even by seeing if the remainder when divided by 2 is zero.
Fill all three blanks to create a dictionary comprehension that converts keys to uppercase, keeps values, and filters values greater than 0.
result = { [1]: [2] for k, v in data.items() if v [3] 0 }k.upper() converts keys to uppercase. We keep the value v as is. The condition v > 0 filters only positive values.