Python Programming Exercises: Functions, Files, and Basic Concepts, Exams of Advanced Education

A collection of multiple-choice questions and exercises covering fundamental python programming concepts. topics include functions, file handling, exception handling, lists, strings, and basic programming constructs. it's valuable for reinforcing understanding and practicing problem-solving skills in python.

Typology: Exams

2024/2025

Available from 05/08/2025

LectJack3
LectJack3 🇺🇸

5

(1)

974 documents

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Introduction to Python Programming
LATEST UPDATE!!!
A design technique that helps to reduce the duplication of code within a program and is
a
benefit of using functions is .
1. code reuse
2. divide and conquer
3. debugging
4. facilitation of teamwork - A
The first line of a function definition is known as the .
1. body
2. introduction
3. initialization
4. header - D
You ____ a function to execute it.
1. define
2. call
3. import
4. export - B
A ____ is a variable that is created inside a function.
1. global variable
2. local variable
3. hidden variable
4. none of the above; you cannot create a variable inside a function - B
A(n) _____ is the part of a program in which a variable may be accessed.
1. declaration space
2. area of visibility
3. scope
4. mode - C
A(n) _____ is a piece of data that is sent into a function.
1. argument
2. parameter
3. header
4. packet - A
A(n) ____ is a special variable that receives a piece of data when a function is called.
1. argument
2. parameter
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Python Programming Exercises: Functions, Files, and Basic Concepts and more Exams Advanced Education in PDF only on Docsity!

Introduction to Python Programming

LATEST UPDATE!!!

A design technique that helps to reduce the duplication of code within a program and is a benefit of using functions is.

  1. code reuse
  2. divide and conquer
  3. debugging
  4. facilitation of teamwork - A The first line of a function definition is known as the.
  5. body
  6. introduction
  7. initialization
  8. header - D You ____ a function to execute it.
  9. define
  10. call
  11. import
  12. export - B A ____ is a variable that is created inside a function.
  13. global variable
  14. local variable
  15. hidden variable
  16. none of the above; you cannot create a variable inside a function - B A(n) _____ is the part of a program in which a variable may be accessed.
  17. declaration space
  18. area of visibility
  19. scope
  20. mode - C A(n) _____ is a piece of data that is sent into a function.
  21. argument
  22. parameter
  23. header
  24. packet - A A(n) ____ is a special variable that receives a piece of data when a function is called.
  25. argument
  26. parameter
  1. header
  2. packet - B A variable that is visible to every function in a program file is a.
  3. local variable
  4. universal variable
  5. program-wide variable
  6. global variable - D When possible, you should avoid using _____ variables in a program.
  7. local
  8. global
  9. reference
  10. parameter - B This is a prewritten function that is built into a programming language.
  11. standard function
  12. library function
  13. custom function
  14. cafeteria function - B This standard library function returns a random integer within a specified range of values.
  15. random
  16. randint
  17. random_integer
  18. uniform - B This statement causes a function to end and sends a value back to the part of the program that called the function.
  19. end
  20. send
  21. exit
  22. return - D This type of function returns either True or False.
  23. Binary
  24. true_false
  25. Boolean
  26. logical - C Calling a function and defining a function mean the same thing. - F A statement in one function can access a local variable in another function. - F
  1. exception generator
  2. exception manipulator
  3. exception handler
  4. exception monitor - C You write this statement to respond to exceptions.
  5. run/handle
  6. try/except
  7. try/handle
  8. attempt/except - B When you open a file that file already exists on the disk using the 'w' mode, the contents of the existing file will be erased. - T The process of opening a file is only necessary with input files. Output files are automatically opened when data is written to them. - F If you do not handle an exception, it is ignored by the Python interpreter, and the program continues to execute. - F You can have more than one except clause in a try/except statement. - T The else suite in a try/except statement executes only if a statement in the try suite raises an exception. - F The finally suite in a try/except statement executes only if no exceptions are raised by statements in the try suite. - F This term refers to an individual item in a list.
  9. element
  10. bin
  11. cubbyhole
  12. slot - A This is a number that identifies an item in a list.
  13. element
  14. index
  15. bookmark
  16. identifier - B This is the first index in a list.
  1. The size of the list minus one - C This is the last index in a list.
  2. 1
  3. 99
  4. 0
  5. The size of the list minus one - D This will happen if you try to use an index that is out of range for a list.
  6. A ValueError exception will occur.
  7. An IndexError exception will occur.
  8. The list will be erased and the program will continue to run. 479
  9. Nothing—the invalid index will be ignored. - B This function returns the length of a list.
  10. length
  11. size
  12. len
  13. lengthof - C This list method adds an item to the end of an existing list.
  14. add
  15. add_to
  16. increase
  17. append - D If you call the index method to locate an item in a list and the item is not found, this happens.
  18. A ValueError exception is raised.
  19. An InvalidIndex exception is raised.
  20. The method returns −1.
  21. Nothing happens. The program continues running at the next statement. - A This file object method returns a list containing the file's contents.
  22. to_list
  23. getlist
  24. readline
  25. readlines - D Which of the following statements creates a tuple?
  26. values = [1, 2, 3, 4]
  27. values = {1, 2, 3, 4}
  28. values = (1)
  1. fatal - C A____ is a sequence of characters.
  2. char sequence
  3. character collection
  4. string
  5. text block - C A ____ is a name that references a value in the computer's memory.
  6. variable
  7. register
  8. RAM slot
  9. byte - A A string literal in Python must be enclosed in.
  10. parentheses.
  11. single-quotes.
  12. double-quotes.
  13. either single-quotes or double-quotes. - D Short notes placed in different parts of a program explaining how those parts of the program work are called.
  14. comments
  15. reference manuals
  16. tutorials
  17. external documentation - A A(n) _____ makes a variable reference a value in the computer's memory.
  18. variable declaration
  19. assignment statement
  20. math expression
  21. string literal - B This symbol marks the beginning of a comment in Python.
  22. &
  23. **
  24. - D

Which of the following statements will cause an error?

  1. x = 17
  2. 17 = x
  3. x = 99999
  4. x = '17' - B

In the expression 12 + 7, the values on the right and left of the + symbol are called.

  1. operands
  2. operators
  3. arguments
  4. math expressions - A This operator performs integer division.
  5. //
  6. %
  7. **
  8. / - A This is an operator that raises a number to a power.
  9. %
  10. **
  11. / - C This operator performs division, but instead of returning the quotient it returns the remainder.
  12. %
  13. **
  14. / - A Suppose the following statement is in a program: price = 99.0. After this statement executes, the price variable will reference a value of which data type?
  15. int
  16. float
  17. currency
  18. str - B Which built-in function can be used to read input that has been typed on the keyboard?
  19. input()
  20. get_input()
  21. read_input()
  22. keyboard() - A Which built-in function can be used to convert an int value to a float?
  23. int_to_float()
  24. float()
  25. convert()
  26. int() - B A magic number is.
  1. conditional
  2. ternary - A A(n) structure tests a condition and then takes one path if the condition is true, or another path if the condition is false.
  3. if statement
  4. single alternative decision 211
  5. dual alternative decision
  6. sequence - C and, or, and not are operators.
  7. relational
  8. logical
  9. conditional
  10. ternary - C A compound Boolean expression created with the ____ operator is true if either of its subexpressions is true.
  11. and
  12. or
  13. not
  14. either - B You can write any program using only sequence structures - F A program can be made of only one type of control structure. You cannot combine structures - F A single alternative decision structure tests a condition and then takes one path if the condition is true, or another path if the condition is false. - F A decision structure can be nested inside another decision structure. - T A compound Boolean expression created with the and operator is true only when both subexpressions are true. - T The while loop is a ____ type of loop.
  15. pretest
  16. no-test
  17. prequalified
  18. post-iterative - A A(n) loop has no way of ending and repeats until the program is interrupted.
  19. indeterminate
  1. interminable 265
  2. infinite
  3. timeless - C The -= operator is an example of a(n) operator.
  4. relational
  5. augmented assignment
  6. complex assignment
  7. reverse assignment - B A(n) ____ is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list.
  8. sentinel
  9. flag
  10. signal
  11. accumulator - A A condition-controlled loop always repeats a specific number of times - F The while loop is a pretest loop. - T The following statement subtracts 1 from x: x = x − 1 - T It is not necessary to initialize accumulator variables. - F In a nested loop, the inner loop goes through all of its iterations for every single iteration of the outer loop. - T To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops. - F In an inheritance relationship, the ___ is the general class.
  12. subclass
  13. superclass
  14. slave class
  15. child class - B In an inheritance relationship, the ___ is the specialized class.
  16. superclass
  17. master class
  18. subclass
  19. parent class - C
  1. object-centric
  2. objective
  3. procedural
  4. object-oriented - D A(n) ____ is a component of a class that references data.
  5. method
  6. instance
  7. data attribute
  8. module - C An object is a(n).
  9. blueprint
  10. cookie cutter
  11. variable
  12. instance - D By doing this, you can hide a class's attribute from code outside the class.
  13. avoid using the self parameter to create the attribute
  14. begin the attribute's name with two underscores 634
  15. begin the name of the attribute with private_ _
  16. begin the name of the attribute with the @ symbol - B A(n) ____ method gets the value of a data attribute but does not change it.
  17. retriever
  18. constructor
  19. mutator
  20. accessor - D
  21. A(n) ____ method stores a value in a data attribute or changes its value in some other way.
  22. modifier
  23. constructor
  24. mutator
  25. accessor - C The ___ method is automatically called when an object is created.
  26. _ init _
  27. init
  28. _ str _
  29. _ object _ - A If a class has a method named _ str _, which of these is a way to call the method?
  30. you call it like any other method: object._ str _()
  31. by passing an instance of the class to the built in str function
  1. the method is automatically called when the object is created
  2. by passing an instance of the class to the built-in state function - B A set of standard diagrams for graphically depicting object-oriented systems is provided by 1. the Unified Modeling Language
  3. flowcharts
  4. pseudocode
  5. the Object Hierarchy System - A The practice of procedural programming is centered on the creation of objects - F Object reusability has been a factor in the increased use of object-oriented programming. - T It is a common practice in object-oriented programming to make all of a class's data attributes accessible to statements outside the class. - F A class method does not have to have a self parameter. - F Starting an attribute name with two underscores will hide the attribute from code outside the class. - T The keys in a dictionary must be mutable objects. - F Dictionaries are not sequences. - T A tuple can be a dictionary key. - T A list can be a dictionary key. - F The following statement creates an empty dictionary: mydct = {} - T You can use the ____ operator to determine whether a key exists in a dictionary.
  6. &
  7. in
  8. ˆ 4.? - B You use ____ to delete an element from a dictionary
  9. the remove method
  10. the erase method
  11. the delete method
  12. the del statement - D