Skip to main content

Exercises 2.15 Multiple Choice Questions

1.

    csp-10-2-1: What is the value of 15 / 12?
  • 1
  • Try again, this is the answer for 15 // 12.
  • 1.25
  • 15 / 12 will result in 1.25. The / operator returns a floating point result.
  • 1.5
  • Try running this in your python interpreter.
  • 3
  • Try again, this is the answer for 15 % 12.

2.

    csp-10-2-2: What is the value of 15 // 12?
  • 1
  • The // operator returns an integer result (the floor).
  • 1.25
  • Try again, this is the answer for 15 / 12.
  • 1.5
  • Try running this in your python interpreter.
  • 3
  • Try again, this is the answer for 15 % 12.

3.

    csp-10-2-3: What is the value of 15 % 12?
  • 1
  • Try again, this is the answer for 15 // 12.
  • 1.25
  • Try again, this is the answer for 15 / 12.
  • 1.5
  • Try running this in your python interpreter.
  • 3
  • The % (modulo) operator returns the remainder and 12 goes into 15 one time with a remainder of 3.

4.

    csp-10-2-4: What is the data type of 'this is what kind of data'?
  • Character
  • It is not a single character.
  • Integer
  • The data is not numeric.
  • Float
  • The value is not numeric with a decimal point.
  • String
  • Strings can be enclosed in single quotes.

5.

    csp-10-2-5: What is printed when the following statements execute?
    day = "Thursday"
    day = 32.5
    day = 19
    print(day)
    
  • Nothing is printed. A runtime error occurs.
  • It is legal to change the type of data that a variable holds in Python.
  • Thursday
  • This is the first value assigned to the variable day, but the value is changed.
  • 32.5
  • This is the second value assigned to the variable day, but the value is changed.
  • 19
  • The current value of the variable day will be printed.

6.

    csp-10-2-6: What is printed when the following statements execute?
    n = input("Please enter your age: ")
    # user types in 18
    print ( type(n) )
    
  • <class 'str'>
  • All input from users is read in as a string.
  • <class 'int'>
  • Even though the user typed in an integer, it does not come into the program as an integer.
  • <class 18>
  • 18 is the value of what the user typed, not the type of the data.
  • 18
  • 18 is the value of what the user typed, not the type of the data.

7.

    csp-10-2-7: What is the value of the following expression:
    16 - 2 * 5 // 3 + 1
    
  • 14
  • Using parentheses, the expression is evaluated as (2*5) first, then (10 // 3), then (16-3), and then (13+1).
  • 24
  • Remember that * has precedence over -.
  • 3
  • Remember that // has precedence over -.
  • 13.667
  • Remember that // does integer division.

8.

    csp-10-2-8: After the following statements, what are the values of x and y?
    x = 15
    y = x
    x = 22
    
  • x is 15 and y is 15
  • Look at the last assignment statement which gives x a different value.
  • x is 22 and y is 22
  • No, x and y are two separate variables. Just because x changes in the last assignment statement, it does not change the value that was copied into y in the second statement.
  • x is 15 and y is 22
  • Look at the last assignment statement, which reassigns x, and not y.
  • x is 22 and y is 15
  • Yes, x has the value 22 and y the value 15.

9.

    csp-10-2-9: Given the following code segment, what will be printed?
    street = "125 Main Street"
    print("The address is " + "street")
    
  • The address is street
  • Since street is in double quotes it will print the string street rather than the value of the variable street.
  • The address is 125 Main Street
  • This would be true if it was print("The address is " + street)
  • It won't execute
  • While this isn't printing what we probably want it to, it will print something.

10.

11.

    csp-10-2-11: Given the following code segment, what will be printed?
    friends = 4
    name = "Derrik"
    print("name" + " has " + str(friends) + " friends")
    
  • Derrick has 4 friends
  • Since name is in quotes it will print those characters rather than the value of name.
  • name has 4 friends
  • Since name is in quotes it will print those characters rather than the value of name, but it will print the value of friends after it converts it to a string.
  • name has friends friends
  • This would be true if both name and friends were in quotes.
  • There will be an error
  • This would be true if the friends can not been converted to a string

12.

    csp-10-2-12: Given the following code segment, what will be printed?
    pets = 2
    name = "Mariah"
    print(name + " has " + pets + " pets")
    
  • Mariah has 2 pets
  • This would be true if there wasn't an error
  • name has 2 pets
  • This would be true if name was in quotes
  • Mariah has pets pets
  • This would be true if pets was in quotes
  • There will be an error
  • You can't concatenate an integer with a string. You need to convert it to a string first.