0% found this document useful (0 votes)
2 views

Advanced Programming

Uploaded by

c5r44n8jq5
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Advanced Programming

Uploaded by

c5r44n8jq5
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Choose the right answer:

1. A ______ is a collection which is ordered and unchangeable and written with round brackets.
A. Tuple
B. Set
C. Directory
D. List
2. A _____ is a collection which is unordered and unindexed and written with curly brackets
A. Tuple
B. Set
C. Directory
D. List
3. A _____ is a collection which is unordered, changeable, and indexed. They are written with curly
brackets and have keys and values.
A. Tuple
B. Set
C. Directory
D. List
4. ASCII stands for:
A. American Casual Code for Data
B. British Casual Code for Data
C. British Standard Code for Information
D. American Standard Code for Information
5. The operation to join two strings is performed with the following operator:
A. The * operator
B. The + operator
C. The / operator
D. None of the above
6. The operation to replicate a string is performed with the following operator:
A. The * operator
B. The + operator
C. The / operator
D. None of the above
7. The isalpha() method produces true output only if:
A. The string contains digits only
B. The string contains letters only
C. The string is a mix of letters and digits
D. None of the above
8. In general, there are two types of files and they are:
A. Text
B. Binary
C. A and B
D. None of the above
9. The operation of connecting the stream with a file is called:
A. Inserting the file
B. Locating the file
C. Editing the file
D. Opening the file
10. The operation disconnecting the stream from the file is called:
A. Closing the file
B. Editing the file
C. Locating the file
D. Inserting the file
11. Using a module in another code is done by the keyword:
A. Add
B. Import
C. Insert
D. Join
12. Which of the following is a key aspect of secure coding:
A. Least privilege
B. Separation of duties
C. Data encryption
D. All of the above
13. Users and components should only be granted the minimum permissions necessary to perform
their intended tasks is known as:
A. Least privilege
B. Data encryption
C. Regular security testing
D. Strong authentication and authorization
14. Benefits of secure coding includes:
A. Reduced risk of data breaches
B. Improved compliance
C. Enhanced brand reputation
D. All of the above
15. Validating input against a predefined set of allowed or disallowed values is known as:
A. Input sanitization
B. Unput length and size limit
C. Whitelisting and blacklisting
D. Data type validation
16. _______ refers to the combining of data and code into a single object
A. Encapsulation
B. Data hiding
C. Procedures
D. None of the above
17. Techniques for organizing and storing data in computer memory.
A. Algorithms
B. Data structure
C. Stack
D. Storage patterns
18. _________ are those data structures which are created using primitive data structures.
A. Primitive data structures
B. Non-primitive data structure
C. Linear data structure
D. Non-linear data structure
19. A data structure is said to be ______ if the data are not arranged in sequence or a linear.
E. Primitive data structure
F. Non-primitive data structure
G. Linear data structure
H. Non-linear data structure
20. An operation that checks if the stack is empty or not.
A. IsEmpty
B. Range
C. Size
D. Count
21. Consider the following: numbers = list(range(5)) the output will be:
A. [1,2,3,4]
B. [0,1,2,3]
C. [0,1,2,3,4]
D. [5,5,5,5]
22. What is the output of the following repetition operator: numbers = [0] * 4
A. [0,0,0,0]
B. [1,2,3,4]
C. [0,1,2,3]
D. [4,4,4,4]
23. A method that is used to reverse the order of the list.
A. Copy()
B. Insert()
C. Reverse()
D. Remove()
24. A ______ is a linear data structure that follows the First-in First-out (FIFO) principle.
A. Set
B. Queue
C. List
D. Data structure
25. ______ is a linear data structure that uses either first-in and last-out (FILO) or last-in and first-out
(LIFO).
A. Tuple
B. Dictionary
C. Stack
D. Set
26. An _______ is a step by step instructions that define a procedure to achieve a specific output.
A. Algorithm
B. Data structure
C. Stack
D. Storage patterns

Answer with true and false:

1. Negative indexing means beginning from the end (True)


2. Once a tuple is created, you can change its values or add new items to it (False)
3. Sets are unordered which means that the elements in a set are not stored in any particular order
(True)
4. You can access items in a set by referring to an index of the item (False)
5. The isdigit() method produces true output only if the string contains digit values (True)
6. The islower() method accepts lower-case letters only (True)
7. The isupper() method accepts upper-case letters only (True)
8. Two strings are equal when the consist of different characters in different order (False)
9. “r” method for opening a file opens a file for reading (True)
10. “w” method for opening a file opens a file for appending (False)
11. “a” method for opening a file opens a file for writing (False)
12. A global namespace is created when the program starts and exists until the program is
terminated (True)
13. “from math import pi” will import all the entities in the math module (False)
14. Object-oriented programming is centered on creating objects (True)
15. Encapsulation refers to an object’s ability to hide its data attributes from code that is outside the
object (False)

Answer the following questions:

1. My_list = [20, 2, 10, 40, 5]


Print(‘The highest value is’, max(my_list))
The highest value is 40

2. My_list = [1,2,3,4,5]
My_list.reverse()
Print(‘Reversed order: ‘, my_list)
Reversed order: [5,4,3,2,1]

3. My_list = [9,1,0,2,8]
My_list.sort()
Print(‘Sorted order:’, my_list)
Sorted order: [0,1,2,8,9]
4. What is the difference between Enqueue and Dequeue?
Enqueue: adds an item to the end of the queue. If the queue is already full, it results
in an overflow condition.
Dequeue: removes an item from the front of the queue. If the queue is empty, it results in
an underflow condition.

5. Design an algorithm to add two numbers and display the result?

Step 1 – start

Step 2 – declare three integers a, b & c

Step 3 – define values of a & b

Step 4 – add values of a & b

Step 5 – store the output of step 4 to c

Step 6 – print c

Step 7 – stop

6. Use the bubble sort algorithm to sort the following numbers: [5, 3, 4, 1, 2]
First pass:
53412
We compare 5 and 3 and swap because 5 is bigger than 3
35412
We compare 5 and 4 and swap because 5 is bigger than 4
34512
We compare 5 and 1 and swap because 5 is bigger than 1
34152
We compare 5 and 2 and swap because 5 is bigger than 2
34125
Second pass:
34125
We compare 3 and 4 but we don’t swap because 3 is smaller than 4
34125
We compare 4 and 1 and swap because 4 is bigger than 1
31425
We compare 4 and 2 and swap because 4 is bigger than 2
31245
We compare 4 and 5 but we don’t swap because 4 is smaller than 5
Third pass:
31245
We compare 3 and 1 and swap because 3 is bigger than 1
13245
We compare 3 and 2 and swap because 3 is bigger than 2
12345
7. Name briefly 3 characteristics of an algorithm?
 Clear and Unambiguous
 Well-Defined Inputs
 Well-Defined Outputs
 Finite-ness
 Feasible
 Language Independent
8. Name 3 advantages of an algorithm?
 It is easy to understand.
 Algorithm is a step-wise representation of a solution to a given problem.
 In Algorithm the problem is broken down into smaller pieces or steps hence, it is
easier for the programmer to convert it into an actual program.

You might also like