1. What is the correct file extension for Python files?
(a) . pp (b).pt (c) .py (d).pyt
2. Which character is used to define a Python comment?
(a)* (b) # (c)$ (d) &
3. What is a correct way to declare a Python variable?
(a) var x = 5 (b) #x = 5 (c) $x = 5 (d) x = 5
4. x = "John" is the same as x = 'John'
(a) True (b) False
5. a = 5 is the same as A = 5
(a) True (b) False
6. Which keyword is used to create a function in Python language?
(a) Function (b) def (c) Func (d) Define
7. What will be the output of the following Python statement?
print("a" + "bc")
a) bc b) abc c) a d) bca
8. Which one of the following is not a reserved word in Python language?
a) pass b) eval c) assert d) nonlocal
9. Which of the following is a Python tuple?
a) {1, 2, 3} b) {} c) [1, 2, 3] d) (1, 2, 3)
10. Which is the correct operator for (xy) in Python?
a) x^y b) x**y c) xey d) None of the mentioned
11. What is the answer to this expression, 22 % 3?
a) 7 b) 1 c) 0 d) 5
12. What is the output of this expression, 3*1**3?
a) 27 b) 9 c) 3 d) 1
13. What is the output for this expression?
name = "ada lovelace"
print([Link]())
a) Ada lovelace b) Ada Lovelace c) ADA LOVELACE d) ada lovelace
14. What is the output for this expression?
name = "ada lovelace"
print([Link]())
a) Ada lovelace b) Ada Lovelace c) ADA LOVELACE d) ada lovelace
15. What is the output for this expression?
SUNYANI TECHNICAL UNIVERSITY 1 of 6 BTEE 209: COMPUTER PROGRAMMING
name = "ada lovelace"
print([Link]())
a) Ada lovelace b) Ada Lovelace c) ADA LOVELACE d) ada lovelace
16. What does an if statement evaluate?
a) A condition that results in True or False b) A variable c) A string d) None of the above
17. What will be the result of the following code:
print(int(35.88))
a)35 b)35.88 c)36 d) 35.8
18. What will be the result of the following code:
print(float(35))
a)35 b) 35.0 c) 0.35 d) 35e0
19. What will be the result of the following code:
x = 'Welcome'
y = 'Coders'
print(x + y)
a) Welcome Coders b) WelcomeCoders c) welcomecoders d) Syntax error
20. Consider this code:
a = 'Join'
b = 'the'
c = 'party'
What is a correct syntax to print 'Join the party'?
a) print(a + b + c) b) print(a + ' ' + b + ' ' + c) c) print(a b c) d) print(“abc”)
21. If x = 5, what is a correct syntax for printing the data type of the variable x?
a) print(dtype(x)) b) print(type(x)) c) print([Link]()) d) print(typex)
22. What will be the outcome of the code?
Cars = [“bmw”,” audi”, “toyota”, “subaru”]
[Link]()
print(cars)
a) [“subaru”, “toyota”, “audi”, “bmw”]
b) [“bmw”, “audi”, “toyota”, “subaru”]
c) [“subaru”, “audi”, “toyota”, “bmw”]
d) [“audi”, “bmw”, “subaru”, “toyota”]
23. When does the else statement execute?
(a) When the if condition is True (b) When the if condition is False
(c) Always (d) when there are ten conditions
24. What will be the result of the following syntax:
print(5 > 3)
(a) True (b) False (c) 5 > 3 (d) none of the answers provided
SUNYANI TECHNICAL UNIVERSITY 2 of 6 BTEE 209: COMPUTER PROGRAMMING
25. Who developed Python, and when was it first released?
(a) Guido van Rossum, 1991 (b) James Gosling, 1995
(c) Brendan Eich, 1995 (d) Linus Torvalds, 1991
26. Who maintains Python today?
(a) Guido van Rossum (b) Python Software Foundation
(c) Microsoft (d) Google
27. What is the output of the following Python code?
x = 10
y = 5
print(x // y)
(a) 2 (b) 1 (c) 2.5 (d) Error
28. What is the output of the following code?
x = "Python"
y = "Programming"
z = x + " " + y
print(z)
(a) PythonProgramming (b) Python Programming (c) Python-Programming (d) Error
29. Which method is used to add an element to a list in Python?
(a) append() (b) add() (c) insert() (d) extend()
30) What will be the output of this code?
age = 19
if age >= 18:
print("You are old enough to vote!")
print("Have you registered to vote yet?")
else:
print(“You are not old enough to vote!)
(a) You are not old enough to vote!
(b) Have you registered to vote yet?
(c) Syntax error
(d) You are old enough to vote!
Have you registered to vote yet?
31) What will be the output of this code?
age = 17
if age >= 18:
print("You are old enough to vote!")
print("Have you registered to vote yet?")
else:
print(“You are not old enough to vote!)
(a) You are not old enough to vote!
(b) Have you registered to vote yet?
(c) Syntax error
SUNYANI TECHNICAL UNIVERSITY 3 of 6 BTEE 209: COMPUTER PROGRAMMING
(d) You are old enough to vote!
Have you registered to vote yet?
32. What will be the outcome of this code?
print("Languages:\n\tPython\n\tC\n\tJavaScript")
(a) Languages:
Python C JavaScript
(b) Languages:
Python
C
JavaScript
(c) Languages: Python C JavaScript
(d) Languages: Python
C
JavaScript
33. What will be outcome of this code?
thislist = ["apple", "banana", "cherry"]
print(“thislist”)
(a) thislist (b) apple, banana, cherry (c) ['apple', 'banana', 'cherry'] d) ['apple', 'banana']
34. What will be outcome of this code?
thislist = ["apple", "banana", "cherry"]
print(thislist)
(a) syntax error (b) apple, banana, cherry
(c) ['apple', 'banana', 'cherry'] (d) ['apple', 'banana']
35. What will be the outcome of this code?
thislist = ["apple", "banana", "cherry"]
len(thislist)
(a)3 (b) len(thislist) (c) thislist (d) 2
36. What will be the outcome of this code?
age = 23
message = "Happy " + age + "rd Birthday!"
print(message)
(a) message (b) Happy 23rd Birthday! (c) Syntax error (d) happy birthday
37. What will be the result of the following syntax:
mylist = ['apple', 'banana', 'cherry']
print(mylist[1])
(a) banana (b) apple (c) 1 (d) mylist1
38. What will be the result of the following syntax:
thislist = ["apple", "banana", "cherry"]
print(thislist[-1])
(a) apple (b) cherry (c) thislist[-1] (d) banana
SUNYANI TECHNICAL UNIVERSITY 4 of 6 BTEE 209: COMPUTER PROGRAMMING
39. What will be the result of the following syntax:
thislist = ["apple", "banana", "cherry", "orange", "kiwi",
"melon", "mango"]
[Link]()
print(thislist)
(a) ['cherry', 'orange', 'kiwi', 'banana', 'melon', 'mango', 'apple']
(b) ['apple', 'banana', 'cherry', 'kiwi', 'mango', 'melon']
(c) ['apple', 'banana', 'cherry', 'orange', 'kiwi', 'melon']
(d) ['apple', 'banana', 'cherry', 'kiwi', 'mango', 'melon', 'orange']
40. What will be the result of the following syntax:
thislist = ["apple", "banana", "cherry", "orange", "kiwi",
"melon", "mango"]
del thislist[0]
print(thislist)
(a) ['apple', 'banana', 'cherry', 'kiwi', 'melon', 'orange']
(b) ['apple', 'cherry', 'kiwi', 'mango', 'melon', 'orange']
(c) ['banana', 'cherry', 'orange', 'kiwi', 'melon', 'mango']
(d) ['apple', 'banana', 'cherry', 'mango', 'melon', 'orange']
SECTION B (20 MARKS)
Answer all questions in this section
1. Imagine you are playing a game where people are to guess a colour. Create a variable called
guess_colour and assign it to a value of 'green’. Write a code to test whether the guessed
colour is green. If it is, print a message to the player that they have guessed the right colour
and as a result they have earned 5 points. If the guessed colour is wrong, tell the player it is
wrong.
(10 marks)
2. A friend of yours is setting up an amusement park. He has given you the rates for admission
into the park as:
Admission for anyone under age 4 is free
Admission for anyone from 4 to 18 is 15 cedis
Admission for anyone above 18 is 20 cedis
Write a python code which asks people for their age and uses it to determine how much they
will pay for admission into the amusement park. (10 marks)
SUNYANI TECHNICAL UNIVERSITY 5 of 6 BTEE 209: COMPUTER PROGRAMMING
1. C 33. A
2. B 34. C
3. D 35. A
4. A 36. C
5. B 37. A
6. B 38. B
7. B 39. D
8. B 40. C
9. D
10. B
11. B
12. C
13. B
14. C
15. D
16. A
17. A
18. B
19. B
20. B
21. B
22. A
23. B
24. A
25. A
26. B
27. A
28. B
29. A
30. D
31. A
32. B
SECTION B
1. guess_colour = "green" 2 marks
b = input ("Guess a colour:") 2 marks
if a == b: 2 marks
print ("You guessed the right colour") 1 mark
print("You have earned 5 points") 1 mark
else: 1 mark
print("You guessed the wrong colour") 1 mark
SUNYANI TECHNICAL UNIVERSITY 6 of 6 BTEE 209: COMPUTER PROGRAMMING
2. age = input("How old are you?:") 2 marks
age = int(age) 1 mark
if age < int(4): 1 mark
print("Your admission is free") 1 mark
elif age <= int(18): 1 mark
print("You will pay 15 cedis") 1 mark
else: 1 mark
age > int(18) 1 mark
print("You will pay 20 cedis") 1 mark
SUNYANI TECHNICAL UNIVERSITY 7 of 6 BTEE 209: COMPUTER PROGRAMMING