Docsity

Computer Science — Python Programming, Algorithms, Data Structures, Object-Oriented Progr, Exams of Programming Methodologies

Toggle sidebar
bg1
PYTHON PROGRAMMING AND
COMPUTER SCIENCE FUNDAMENTALS
PRACTICE EXAM.
Computer Science — Python Programming, Algorithms,
Data Structures, Object-Oriented Programming,
Databases and Software Development.
QUESTIONS.
1. Python Variable
Which statement correctly assigns the value 10 to a variable named score?
A. score == 10
B. score = 10
C. set score 10
D. int score = 10
2. Python Data Type
Which data type is immutable?
A. List
B. Dictionary
C. Set
D. Tuple
3. List
Which structure is ordered and mutable?
A. List
B. Tuple
C. String only
D. Frozen set
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Computer Science — Python Programming, Algorithms, Data Structures, Object-Oriented Progr and more Exams Programming Methodologies in PDF only on Docsity!

PYTHON PROGRAMMING AND

COMPUTER SCIENCE FUNDAMENTALS

PRACTICE EXAM.

Computer Science — Python Programming, Algorithms,

Data Structures, Object-Oriented Programming,

Databases and Software Development.

QUESTIONS.

1. Python Variable Which statement correctly assigns the value 10 to a variable named score? A. score == 10 B. score = 10 C. set score 10 D. int score = 10 2. Python Data Type Which data type is immutable? A. List B. Dictionary C. Set D. Tuple 3. List Which structure is ordered and mutable? A. List B. Tuple C. String only D. Frozen set

4. Dictionary A Python dictionary stores data as: A. Unordered characters only B. Key-value pairs C. Numeric indexes only D. Functions only 5. Set A set is useful when a programmer needs: A. Duplicate values in a fixed order B. Unique elements without relying on duplicate entries C. Key-value pairs with duplicate keys D. A sequence that cannot change 6. Conditional Statement Which keyword begins a conditional statement in Python? A. if B. when C. condition D. check 7. Loop Which loop is commonly used to iterate over the items in a sequence? A. repeat B. for C. iterate D. cycle 8. While Loop A while loop continues executing while:

13. Exception Which keyword is used to handle exceptions? A. try B. catch C. error D. handle 14. Finally Block A finally block generally: A. Executes whether or not an exception occurs B. Runs only if the program has no errors C. Defines a class D. Deletes a variable 15. Module A Python module is: A. A file containing reusable Python code B. A hardware component C. A database password D. A loop condition 16. Import Which statement imports the math module? A. include math B. load math C. import math D. use math module 17. List Indexing In Python, the first element of a list normally has index:

A. 1

B. - 1

C. 0

D. 2

18. List Method Which method adds one item to the end of a list? A. append() B. insert_end() C. add_last() D. push_end() 19. List Comprehension A list comprehension is used to: A. Create a list concisely from an iterable B. Encrypt a list C. Delete every variable D. Define a database schema 20. String Method Which method converts a string to lowercase? A. lower() B. small() C. downcase() D. case_lower() 21. Object-Oriented Programming A class is: A. A blueprint for creating objects B. A single numeric value C. A database transaction only D. A loop with no condition

C. Stop every loop D. Import a module

27. Stack A stack follows which principle? A. First in, first out B. Last in, first out C. Random in, random out D. Sorted in, sorted out 28. Queue A queue generally follows: A. Last in, first out B. First in, first out C. Highest value first D. Random access only 29. Binary Search Binary search requires the data to be: A. Randomly arranged B. Sorted C. Encrypted D. Duplicated 30. Binary Search Complexity The typical time complexity of binary search is: A. O(n²) B. O(n) C. O(log n) D. O(1) always 31. Linear Search The worst-case time complexity of a basic linear search is:

A. O(log n) B. O(n) C. O(n²) D. O(1) always

32. Big-O Notation Big-O notation describes: A. How resource requirements grow as input size increases B. The exact running time on every computer C. The programmer’s salary D. The number of comments in code 33. Recursion A recursive function: A. Calls itself directly or indirectly B. Cannot have a return value C. Must use a database D. Always runs faster than iteration 34. Recursion Base Case A base case is necessary to: A. Prevent infinite recursive calls B. Increase memory usage C. Create a class D. Import a package 35. Algorithm An algorithm is: A. A step-by-step procedure for solving a problem B. A computer monitor C. A file extension only D. A password format

C. Encrypting a database D. Designing a logo

41. Version Control Version-control systems help developers: A. Track changes and collaborate on code B. Prevent all bugs automatically C. Replace software testing D. Eliminate the need for documentation 42. Git Commit A Git commit generally: A. Records a set of changes in the repository history B. Deletes the entire repository C. Publishes an application automatically in every case D. Creates a new programming language 43. Secure Coding Which practice improves security when building database queries? A. Use parameterized queries B. Concatenate untrusted input directly into SQL C. Store passwords in plaintext D. Disable input validation 44. Select All That Apply — Code Quality Which practices generally improve code quality? Select all that apply. A. Use meaningful names. B. Write focused functions. C. Add appropriate tests. D. Document important assumptions. E. Duplicate complex code unnecessarily. F. Ignore error handling.

45. NGN-Style Programming Case A Python application crashes when users submit blank form fields. Review shows that the program converts the input directly to an integer without checking whether the field is empty. What is the primary problem? A. Missing input validation and exception handling B. Excessive database normalization C. Too many comments D. A hardware power failure Which two actions should the developer prioritize? A. Validate input before conversion. B. Handle expected conversion errors safely. C. Remove all user input. D. Ignore blank fields. E. Store every input as plaintext credentials. Which two tests should be added? A. Test blank input. B. Test valid numeric input. C. Test the office printer. D. Test employee attendance. E. Test monitor brightness. 46. Virtual Environment A Python virtual environment is useful for: A. Isolating project dependencies B. Replacing source control C. Encrypting all files automatically D. Removing Python from the system 47. Package Manager Which tool is commonly used to install Python packages?

7. B

8. A

9. C

10.A

11.A

12.B

13.A

14.A

15.A

16.C

17.C

18.A

19.A

20.A

21.A

22.A

23.A

24.A

25.A

26.A

27.B

28.B

29.B

30.C

31.B

32.A

33.A

34.A

35.A

36.A

37.A

38.A

39.A

40.A

41.A

42.A

43.A

44.A, B, C, D

45.Problem: A; Actions: A, B; Tests: A, B 46.A

47.A

48.A

49.A

50.C

BRIEF RATIONALES

  1. Assignment uses =; comparison uses ==.
  2. Tuples are immutable, unlike lists, dictionaries and ordinary sets.
  3. Lists are ordered and mutable.
  4. Dictionaries store key-value pairs.
  5. Sets are useful for unique elements.
  6. if begins a conditional block.
  7. for iterates over iterable items.
  8. A while loop runs while its condition remains true.
  9. def defines a function. 10.return exits a function and can provide a result. 11.Parameters are inputs accepted by functions. 12.Local variables are generally limited to their defining function or scope. 13.try begins exception-handling logic. 14.finally runs whether an exception occurs or not. 15.A module is a reusable Python file. 16.import math loads the math module. 17.Python uses zero-based indexing. 18.append() adds an item to the end of a list. 19.List comprehensions create lists concisely. 20.lower() converts alphabetic characters to lowercase. 21.A class is a blueprint for objects. 22.An object is an instance of a class. 23.Encapsulation bundles data and methods while controlling access. 24.Inheritance supports reuse from a parent class. 25.Polymorphism allows different implementations through a common interface. 26.init() initializes object state. 27.Stacks use last-in, first-out behavior. 28.Queues use first-in, first-out behavior. 29.Binary search requires sorted data. 30.Binary search typically runs in O(log n). 31.Linear search can inspect every element, producing O(n) worst-case time.