Computer Science Worksheet
Computer Science Worksheet
a x = 10 b a = 5
if x % 2 == 0: b = 10
print("Even") if a > b:
else: print("A is greater")
elif a == b:
print("Odd") print("A is equal to B")
else:
print("B is greater")
Worksheet 2: Lists
1. Write a program to find the sum of elements in a list.
2. What will be the output of the code below?
my_list = [1, 2, 3]
my_list.append([4, 5])
print(len(my_list))
num = 7 b x = 3
if num % 2 == 0: if x > 5:
print("Even") print("x is greater than 5")
elif num % 3 == 0: elif x == 3:
print("Divisible by 3") print("x is equal to 3")
else: else:
print("Neither even nor print("x is less than 5")
divisible by 3")
Worksheet 3: Strings
1. Write a program to reverse a string.
2. Explain the difference between isalpha() and isdigit() methods with examples.
3. Write the output of the code below:
s = "Python"
print(s[1:4])
x = 4
if x > 3
print("x is greater than 3")
num = 7
if num % 2 == 0
print("Even")
elif num % 3 = 0:
print("Divisible by 3")
Worksheet 4: Dictionaries
1. Write a Python program to merge two dictionaries.
2. Define the following dictionary:
student = {"name": "Alex", "age": 18, "marks": 85}
Worksheet 5: Cybersecurity
1. What is phishing? Explain with an example.
2. How does two-factor authentication improve security?
3. Define the term "malware" and list two examples.
Worksheet 8: Strings
1. Write a Python program to count the frequency of vowels in a string.
2. Explain the difference between find() and index() methods.
3. Predict the output:
text = "AI is fun"
print(text.upper())
Worksheet 9: Dictionaries
1. Write a Python program to check if a given key exists in a dictionary.
2. What will the following code print?
my_dict = {"a": 1, "b": 2}
my_dict["c"] = 3
print(len(my_dict))
4. Write a Python program that removes all duplicate elements from a list.
5. Write a Python program to find the maximum and minimum elements in a list of numbers.
a = 20
b = 15
if a > b
print("a is greater than b")
elif a == b:
print("a is equal to b")
else
print("b is greater than a")
x = 8
if x > 3:
print("x is greater")
else x == 5:
print("x is equal to 5")