Study questions for Midterm Exam CS 115

Not guaranteed to be complete but good to work on! These will not be collected, but you can certainly discuss them with your classmates or your instructor.

The format of these questions is NOT always what you would see on the test. We avoid open-ended, broad questions that would be very hard to grade.

The test will contain some of: multiple choice questions (some), fill in the blank with a word or two, short answer - a sentence or two, what's wrong with this code?, what is the output of this code?, write a statement or expression to do this. Possibly there will be a test plan or truth table to fill out.

  1. Do you know the difference between RAM and a hard drive, and the units to measure capacity and speed?
  2. Write down three legal identifiers. Can you state why each one is legal? Try to use all the rules of identifier creation. Write three invalid identifiers; make each one invalid in a different way.
  3. What does 'case sensitive' mean? does it apply to Python?
  4. Write an assignment statement that has the formula below stored in a variable called result. Use no more parentheses than needed.
    		  a + b - 4e - f  
    
    2a
  5. Trace this code. That is, keep track of what is in memory (Label it "RAM") and what is output (label it "shell"). Another thing to note: can you tell what type of data each variable contains at each point in the program? Variables can change their type!
    
    		v1 = 15.7
    		v3 = int(3 * 5.2)
    		v2 = v1 + v3
    		print ("v2 =", v2, end=" ")
    		v3 = v2 - 5
    		print ("v3 =", v3, sep="")
    		v1 = 8
    		print ("v1 =", v1)
    		v2 = 3 * v1
    		print ("v2 =", v2)
    
  6. What is a block of code? How do you indicate it in Python? What kind of statements use blocks?
  7. Calculate the values of the expressions. Indicate what type the answer is.
    	a.  5 + 4 * (3.2 + 4.5)
    	b.  7 % 5 + 12 // 7
    	c.  8 + 4.0 ** 3
    
  8. Could you answer these questions about the modulus operator? about the // operator? about the ** operator? about the < operator? about the "or" operator?
    1. what type or types of data does it operate on?
    2. what type or types does it return?
    3. what does it do - what are its semantics?
    4. what is its precedence?
  9. What are the "three P's"?
  10. If you want to make a floating point number into an integer, how do you do it? what's the syntax? What about vice versa?
  11. Why is this typecast redundant? x = str(input("what's your name?"))
  12. Why is this typecast redundant? x = float(1/2)
  13. How many times will each of these for loops repeat their body? What values will the variable i go through?
    1. for i in range(10):
    2. for i in range(3, 10, 2):
    3. for i in range(2, 5):
    4. for i in [2,3,5,1,0]:
  14. Tautologies and Contradictions: Can you figure out if an expression is one or the other? Which of these are tautologies? which are contradictions?
                  var > 10 or var < 20
                  var == 5 or 9
                  var < 20 and var > 100
    
  15. Write an expression logically equivalent to not (a > b and c > d) which does not use the not operator. "logically equivalent" means that when one expression is True, the other is, and the same with False. Hint: DeMorgan's Laws
  16. Describe the difference between integers and floating point numbers. Which one does faster arithmetic? why? What is a mantissa?
  17. What is type coercion? when does it happen? What is the output of this program always, regardless of the value of x?
            x = 23
            if x == 10 or 19:
               print("right")
            else:
               print("no")
    
  18. What is an escaped character? Can you name 3 different ones? What does each one mean? (Hint: "\n" is a newline character, that's one)
  19. What are the values of a and b after this code?
    	y = 2.3
    	a = int (y * 2)
    	b = y % a
    	
    
  20. Write a complete program that performs the interaction given. The user enters a number of dollars and the program tells how many pennies that is. Use at least one variable and two assignment statements.
  21. What's the difference between syntax and semantics? How do you find syntax errors? semantics errors?
  22. Who is Guido van Rossum?
  23. Who was George Boole?
  24. List the parts of the IDE that you have used so far. What did you use each one for?
  25. Comments - how do you write them? why do you write them? who reads them?
  26. Name the different data types in Python. How are they different? what are they used for? What do constants of each type look like?
  27. Describe precisely the actions that happen when an assignment statement is executed. That is, what happens first? second?
  28. Describe an accumulator - how is it different from an ordinary assignment statement?
  29. What is an "augmented assignment operator"? What are their precedences?
  30. How do you import a library? there are 3 different forms of the statement. How do they differ? When do you import a library? Hint: ONLY when you need it!
  31. Name some library functions. What type do they require for arguments? what type do they return? How do you call them? (what is the syntax if they return a value? what if they do NOT return a value?)
  32. Describe pseudocode. When is it written? How is it written?
  33. You might see the special value None when?
  34. You have a program that will output "over the limit", "ok" or "too slow" depending on the input of a speed (of a car). It should output "over the limit" when the speed is greater than 70, "ok" between 70 and 40 (inclusive), and "too slow" for speeds less than 40. Write a test plan to test this program. Make sure you include the boundary cases.
  35. What is regression testing? a test plan? What are the columns in a test plan?
  36. What is the output of this code?
            num = 12.3456
            print("The num is {:.3f}".format(num))
    
  37. What is the output of this code with speed = 55?:
            if speed < 40:
                    print("slow")
            elif speed < 55:
                    print("legal")
            else:
                    print("ticket")
    
    
    Write a test plan for this code.
  38. Know the difference between logical and relational operators.
  39. Put parentheses in the expression below so that they show what order the operations will be done in:
        a < 0 and b >= 5 + y or z > 3 and q == p
  40. What is the difference in operation between a "=" operator and a "==" operator? When do you use one and when do you use the other?
  41. Write a design for this problem: Read in three numbers and output the ones that are larger than their average. This should be done with pseudocode, NOT code! no Python at all, just English. Number the steps if you like.
  42. Write the code for the design in the previous problem.
  43. Write a program that will input a number (float) and tell if it is a perfect square or not. Numbers are perfect squares if their square root is an integer. 25 is a perfect square because 5 squared is 25 and 25 is an integer. 2 is not a perfect square because 1.41421 squared is 2 and it is not an integer.
  44. What's the difference between an interpreter and a compiler? Which one will find as many syntax errors as possible when you run it? Which one must be present to do translation every time you run the program?
  45. What's an overloaded symbol? Name one and its various meanings.
  46. Comparisons
  47. What's the difference between a control structure and a data structure?
  48. Name the basic control structures.
  49. What's dead code?
  50. What causes an infinite loop?
  51. What are the guarantees true for EACH control structure? What is the guarantee that is true for ALL control structures?
  52. Trace this code:
               x = 9 // 2      # Line 1
               y = x + 4       # Line 2
               print(x,y)      # Line 3
               if x > 4:       # Line 4
                  y = 17       # Line 5
               if y > 10:      # Line 6
                  print("ok")  # Line 7
               else:           # Line 8
                  print("no")  # Line 9
               print("yes")    # Line 10