Time: 30 minutes
Total Questions: 20
What is the output of this code?
numbers = [1, 2, 3, 4, 5]
print(numbers[-1])
print(numbers[1:3])Write a conditional statement to check if a year is a leap year. (A leap year is divisible by 4, but not by 100 unless also divisible by 400)
How do you create a tuple in Python? Give an example.
Write a for loop that iterates through a list of fruits and prints each fruit.
What is the difference between append() and extend() methods for lists?
Write a function that takes a list and returns the sum of all elements.
How do you check if a value exists in a list? Write code to check if "apple" is in a list of fruits.
Write a while loop that continues until the user enters "quit".
What is the purpose of the break and continue statements in loops?
Write a dictionary with 3 key-value pairs where keys are student names and values are their ages.
How do you get all keys from a dictionary? Write code to print all keys from a dictionary.
Write a function that takes two numbers and returns the larger one.
What is the output of this code?
print(10 % 3)
print(2 ** 4)Write a nested loop to print a multiplication table from 1 to 5.
How do you convert a list to a set? Write the code to do this.
Write a function that takes a string and returns it in uppercase.
What is the difference between and and or operators?
Write code to open a file and read its contents line by line.
How do you create a list of numbers from 0 to 9 using list comprehension?
Write a function that takes a list and returns the average of all numbers.
End of Test Set 5