Docsity

Introduction to Python Programming / PROGRAMMING QUESTIONS & CORRECT SOLUTIONS / RATED A, Exams of C programming

Toggle sidebar
bg1
Introduction to Python Programming /
PROGRAMMING QUESTIONS &
CORRECT SOLUTIONS / RATED A+ /
GUARANTEED PASS
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
iLovePDF
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Introduction to Python Programming / PROGRAMMING QUESTIONS & CORRECT SOLUTIONS / RATED A and more Exams C programming in PDF only on Docsity!

Introduction to Python Programming /

PROGRAMMING QUESTIONS &

CORRECT SOLUTIONS / RATED A+ /

GUARANTEED PASS

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
  1. packet - ✔✔✔ A A(n) ____ is a special variable that receives a piece of data when a function is called.
  2. argument
  3. parameter
  4. header
  5. packet - ✔✔✔ B A variable that is visible to every function in a program file is a.
  6. local variable
  7. universal variable
  8. program-wide variable
  9. global variable - ✔✔✔ D When possible, you should avoid using _____ variables in a program.
  10. local
  11. global
  12. reference
  13. parameter - ✔✔✔ B This is a prewritten function that is built into a programming language.
  14. standard function
  15. library function
  16. custom function
  17. cafeteria function - ✔✔✔ B This standard library function returns a random integer within a specified range of values.
  18. random
  19. randint
  20. random_integer
  21. uniform - ✔✔✔ B This statement causes a function to end and sends a value back to the part of the program that called the function.
  22. end
  23. send
  24. exit
  25. return - ✔✔✔ D This type of function returns either True or False.
  26. Binary
  27. true_false
  28. Boolean

When an exception is generated, it is said to have been.

  1. built
  2. raised
  3. caught
  4. killed - ✔✔✔ B This is a section of code that gracefully responds to exceptions.
  5. exception generator
  6. exception manipulator
  7. exception handler
  8. exception monitor - ✔✔✔ C You write this statement to respond to exceptions.
  9. run/handle
  10. try/except
  11. try/handle
  12. 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.
  13. element
  14. bin
  15. cubbyhole
  16. slot - ✔✔✔ A

This is a number that identifies an item in a list.

  1. element
  2. index
  3. bookmark
  4. identifier - ✔✔✔ B This is the first index in a list.
  5. −
  6. 1
  7. 0
  8. The size of the list minus one - ✔✔✔ C This is the last index in a list.
  9. 1
  10. 99
  11. 0
  12. 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.
  13. A ValueError exception will occur.
  14. An IndexError exception will occur.
  15. The list will be erased and the program will continue to run. 479
  16. Nothing—the invalid index will be ignored. - ✔✔✔ B This function returns the length of a list.
  17. length
  18. size
  19. len
  20. lengthof - ✔✔✔ C This list method adds an item to the end of an existing list.
  21. add
  22. add_to
  23. increase
  24. append - ✔✔✔ D If you call the index method to locate an item in a list and the item is not found, this happens.
  25. A ValueError exception is raised.
  26. An InvalidIndex exception is raised.
  27. The method returns −1.
  28. Nothing happens. The program continues running at the next statement. - ✔✔✔ A This file object method returns a list containing the file's contents.

You can use the for loop to iterate over the individual characters in a string. - ✔✔✔ T When you call a string's split method, the method divides the string into two substrings. - ✔✔✔ F A ___ error does not prevent the program from running, but causes it to produce incorrect results.

  1. syntax
  2. hardware
  3. logic
  4. fatal - ✔✔✔ C A____ is a sequence of characters.
  5. char sequence
  6. character collection
  7. string
  8. text block - ✔✔✔ C A ____ is a name that references a value in the computer's memory.
  9. variable
  10. register
  11. RAM slot
  12. byte - ✔✔✔ A A string literal in Python must be enclosed in.
  13. parentheses.
  14. single-quotes.
  15. double-quotes.
  16. 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.
  17. comments
  18. reference manuals
  19. tutorials
  20. external documentation - ✔✔✔ A A(n) _____ makes a variable reference a value in the computer's memory.
  21. variable declaration
  22. assignment statement
  23. math expression
  24. string literal - ✔✔✔ B

This symbol marks the beginning of a comment in Python.

  1. &
  2. **
  3. - ✔✔✔ 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.
  5. operands
  6. operators
  7. arguments
  8. math expressions - ✔✔✔ A This operator performs integer division.
  9. //
  10. %
  11. **
  12. / - ✔✔✔ A This is an operator that raises a number to a power.
  13. %
  14. **
  15. / - ✔✔✔ C This operator performs division, but instead of returning the quotient it returns the remainder.
  16. %
  17. **
  18. / - ✔✔✔ 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?
  19. int
  20. float
  21. currency
  22. str - ✔✔✔ B
  1. sequence
  2. single alternative decision
  3. one path alternative
  4. single execution decision - ✔✔✔ B A(n) ____ expression has a value of either True or False.
  5. binary
  6. decision
  7. unconditional
  8. Boolean - ✔✔✔ D The symbols >, <, and == are all operators.
  9. relational
  10. logical
  11. conditional
  12. 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.
  13. if statement
  14. single alternative decision 211
  15. dual alternative decision
  16. sequence - ✔✔✔ C and, or, and not are operators.
  17. relational
  18. logical
  19. conditional
  20. ternary - ✔✔✔ C A compound Boolean expression created with the ____ operator is true if either of its subexpressions is true.
  21. and
  22. or
  23. not
  24. 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.

  1. pretest
  2. no-test
  3. prequalified
  4. post-iterative - ✔✔✔ A A(n) loop has no way of ending and repeats until the program is interrupted.
  5. indeterminate
  6. interminable 265
  7. infinite
  8. timeless - ✔✔✔ C The - = operator is an example of a(n) operator.
  9. relational
  10. augmented assignment
  11. complex assignment
  12. 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.
  13. sentinel
  14. flag
  15. signal
  16. 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

A subclass can have a method with the same name as a method in the superclass. - ✔✔✔ T Only the _ init _ method can be overridden. - ✔✔✔ F You cannot use the isinstance function to determine whether an object is an instance of a subclass of a class. - ✔✔✔ F The ____ programming practice is centered on creating functions that are separate from the data that they work on.

  1. modular
  2. procedural
  3. functional
  4. object-oriented - ✔✔✔ B The ____ programming practice is centered on creating objects.
  5. object-centric
  6. objective
  7. procedural
  8. object-oriented - ✔✔✔ D A(n) ____ is a component of a class that references data.
  9. method
  10. instance
  11. data attribute
  12. module - ✔✔✔ C An object is a(n).
  13. blueprint
  14. cookie cutter
  15. variable
  16. instance - ✔✔✔ D By doing this, you can hide a class's attribute from code outside the class.
  17. avoid using the self parameter to create the attribute
  18. begin the attribute's name with two underscores 634
  19. begin the name of the attribute with private_ _
  20. 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.
  21. retriever
  22. constructor
  1. mutator
  2. accessor - ✔✔✔ D
  3. A(n) ____ method stores a value in a data attribute or changes its value in some other way.
  4. modifier
  5. constructor
  6. mutator
  7. accessor - ✔✔✔ C The ___ method is automatically called when an object is created.
  8. _ init _
  9. init
  10. _ str _
  11. _ object _ - ✔✔✔ A If a class has a method named _ str _, which of these is a way to call the method?
  12. you call it like any other method: object._ str _()
  13. by passing an instance of the class to the built in str function
  14. the method is automatically called when the object is created
  15. 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
  16. flowcharts
  17. pseudocode
  18. 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