Comp 115 Test 1 Study Guide

Test on February 11 in lab

I tried my best to list the topics for the exam but I may have forgotten one or two. Your default assumption should be that if I covered it in class on or before Friday February 7, it is fair game for the exam. If you have a specific question about whether a topic could be part of the exam, please come to ask me.

I will add practice problems as I find new interesting questions, so come back to this page every few days, more practice problems may have appeared.

Programs

Values, Variables, Expressions and Assignments

Input and Output

Math with Python

Strings in Python

Removed from test material.

Practice Problems

  1. Are the following valid names (as far as Python is concerned) for a variable?
    • 10more
    • uu123___qwerqwerqwerq
    • __1212__1212
    • IMSCREAMING
    • @comp115
    • variable!

  2. Practice using camel case and snake case for variable names consisting of any 2 or 3 words of your choice.

  3. What is the type or each of the following expressions?
    • 5
    • 4.5
    • "a number"
    • True
    • [1,2,3]
    • 2 * 5
    • 2 + 5.0
    • 54 / 9
    • 35 % 3
    • float(3) + 5

  4. To what value would Python evaluate each of the following expressions?
    • 3 * 5
    • 40 / 8
    • 40 // 8
    • 2 ** 5.0
    • int(2.3) + 5
    • float(7) * 2
    • int(-6.5)
    • round(-6.5)
    • int(-7.5)
    • round(-7.5)

  5. Knowing that sin and cos are functions in the math library, and that pi and e are constants in the math library, write a Python expression that would calculate the following
    • $\cos(x + y)$
    • $e^{2\pi}$
    • $\frac{n+1}{n-1}$
    • $\sin(a^5 + b^5)$

  6. Determine what would be printed on screen as a result of executing the following code:
      userInput1 = int(input("Please enter an integer: "))
      userInput2 = float(input("Please enter a floating-point number: "))
      calc1 = userInput1 ** 2
      calc2 = userInput1 / 5
      calc3 = userInput2 * 3
      print("The first value is", calc1)
      print("The second value is {0:3.1f} calculated from {1}".format(calc2, userInput1))
      print("The last value is {0:3.1f}".format(calc3))
    Assume that the user enters the value 11 and 3.1 as input.

  7. A gas station sells diesel at $2.799 per gallon. Write a program that asks the user how many gallons of diesel they would like to buy and displays the amount. The amount displayed should be rounded to the closest cent, with the 0.5cent rounded up.