Game Preview

110 Arithmetic Expressions + Input/Ouptut

  •  English    12     Public
    Python
  •   Study   Slideshow
  • What would be stored in the variable result after the expression is executed in Python? result = 10**3
    1000
  •  10
  • What would be stored in the variable result after the expression is executed in Python? result = 10//3
    3
  •  10
  • What would be stored in the variable result after the expression is executed in Python? result = 5 // 2 + 4 / 2
    4.0
  •  15
  • What would be stored in the variable result after the expression is executed in Python? result = 6 + 4 * 3 - 2
    16
  •  15
  • The command used in Python to display something to standard output is
    print
  •  10
  • The command used in Python to read in input from standard input is
    input
  •  10
  • Does the following statement work or produce an error message when executed? If it works, what does it display? value1 = 2.0 value2 = 3 print("The sum of ", value1, " and ", value2, "is", value1 + value2)
    The sum of 2.0 and 3 is 5.0
  •  20
  • Does the following statement work or produce an error message when executed? If it works, what does it display? value1 = 2.0 value2 = 3 print("The sum of " + value1 + " and " + value2 + "is" + (value1 + value2))
    Error message TypeError: can only concatenate str (not "float") to str
  •  20
  • Suppose that we want to read in a data value from standard input. What are two things we'd need to consider in order to successfully write the Python statement to accomplish this goal?
    1. What is a meaningful identifier? 2. Is the data going to be a string or a numeric type? 3. What should we say to prompt the user to enter the data?
  •  20
  • Will this statement execute or produce an error message? dataValue = int(input("Enter the quantity of candy bars that you wish to purchase: "))
    Execute
  •  20
  • I'm writing software for a pizza company and pizzas are 6.00. The software will ask the user to enter the number of pizzas that he/she is purchasing and store that as quantityOfPizza. Write an expression to calculate the total cost.
    totalCost = quantityOfPizza * 6.00
  •  20
  • I'm writing software for a pizza company and I want the user to enter his/her phone number. I wrote the following Python statement: phoneNumber = input("Please enter your phone number") Will this work well to store the phone number?
    Yes, phone number will be stored as a string but we are unlikely to perform arithmetic calculations on the number so that's fine.
  •  20