CS Midterm 2

40 flashcards · Computer Science · by Elsa Schutfort

  1. Best test to see if a boolean variable is true (Boolean variable isDone)

    if isDone

  2. A code that displays "Cannot get a driver's license" if age is less than 16

    if age < 16

  3. A code that displays "Can get a driver's license" if age is 16 and up

    if age >= 16 else elif age >= 16

  4. What the result of "True or True and False"

    True

  5. What the result of "True or False and False"

    False

  6. If func1() returns False when would func2() not be called (Boolean values)

    func1() and func2()

  7. Do if-else block have to end with an else?

    No

  8. What equivalent to if number % 2 == 0: even = True else: even = False

    even = number % 2 == 0

  9. What operator results in a Boolean value that is opposite of its operand? (operand is True and results in a False)

    not

  10. What range returns 0, 1, 2, 3, 4, 5

    range(0, 6)

  11. How many times is the print statement executed? for I in range(1,4): for j in range(i): print(I*j)

    6

  12. Will this program terminate and why? value = 10 while True: if value < 8: break value = value - 2

    Yes, value is subtracted by 2 so its not bigger than 8

  13. What does break terminate?

    the entire loop

  14. What does continue terminate?

    only the current iteration of the loop

  15. Is the body of a while loop guaranteed to execute at least one time?

    No

  16. Define iteration

    the term for a single execution of a loop

  17. What are the possible values of random.randint(0,100)

    0 through 100

  18. Define sentinel value

    denotes the end of a data set but not part of the data

  19. What is a step in a range?

    The step is each increment it goes up by

  20. define Formal Parameters

    the name you use to refer to the actual parameter

  21. Formal Parameters syntax

    function(formal parameters)

  22. define Actual Parameters

    values that are passed to a function when it is invoked

  23. Actual Parameters syntax

    function(formal) code function(actual)

  24. define Stack and Heap

    used to organize function calls in a computer

  25. Every time a function is called, data for the function placed on top of the

    stack

  26. Keywords example

    formalParameter=value

  27. Three main purposes of using functions

    Reuse the same code, organize code, and make code simpler

  28. Are return statements are required for functions?

    no

  29. define Arguments

    another term for parameters of a function when it is called

  30. keyword when defining a function

    def function():

  31. How do you call a function that has default arguments?

  32. What is the name of the part of memory that stores objects when a function is called?

    heap

  33. Where are default arguments specified for a function?

    as a formal parameter

  34. When are positional actual parameters used?

    when a function is called with parameters that do not include any keywords.

  35. Importing a function in a module

    from module import function

  36. define local variable

    a variable that is created inside a function

  37. define global variable

    a variable that are created outside of a function

  38. define immutable

    a object is immutable when the value can't be changed over time

  39. immutable examples

    numbers and strings

  40. define Activation Record

    stores parameters and local variables and is part of the program execution management when a function is called