Skip to content

Latest commit

 

History

History
79 lines (55 loc) · 1.94 KB

File metadata and controls

79 lines (55 loc) · 1.94 KB

Python Test Set 5 - Easy

Time: 30 minutes
Total Questions: 20


Question 1

What is the output of this code?

numbers = [1, 2, 3, 4, 5]
print(numbers[-1])
print(numbers[1:3])

Question 2

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)

Question 3

How do you create a tuple in Python? Give an example.

Question 4

Write a for loop that iterates through a list of fruits and prints each fruit.

Question 5

What is the difference between append() and extend() methods for lists?

Question 6

Write a function that takes a list and returns the sum of all elements.

Question 7

How do you check if a value exists in a list? Write code to check if "apple" is in a list of fruits.

Question 8

Write a while loop that continues until the user enters "quit".

Question 9

What is the purpose of the break and continue statements in loops?

Question 10

Write a dictionary with 3 key-value pairs where keys are student names and values are their ages.

Question 11

How do you get all keys from a dictionary? Write code to print all keys from a dictionary.

Question 12

Write a function that takes two numbers and returns the larger one.

Question 13

What is the output of this code?

print(10 % 3)
print(2 ** 4)

Question 14

Write a nested loop to print a multiplication table from 1 to 5.

Question 15

How do you convert a list to a set? Write the code to do this.

Question 16

Write a function that takes a string and returns it in uppercase.

Question 17

What is the difference between and and or operators?

Question 18

Write code to open a file and read its contents line by line.

Question 19

How do you create a list of numbers from 0 to 9 using list comprehension?

Question 20

Write a function that takes a list and returns the average of all numbers.


End of Test Set 5