Homework 3

CHE 116: Numerical Methods and Statistics

2/2/2019


1. String Formatting

  1. [1 point] Using the math module, print euler's number to 5 digits precision in scientific notation format
  2. [1 point] Print the first 5 powers of 7 with exactly 5 spaces starting from $7^1$
  3. [1 point] Create a variable v whose value is None and print it out
  4. [4 points] Use the same variable, v, and print it with 3 digits of precision in scientific notation. You should receive an error. Using the definition of a sentinel value, why would we want to not have an error if printed without formatting (problem 1.3) but receieve an error when we format it?

2. Representing Numbers

  1. [1 point] What is the Manitissa for the number $0.4335 \times 10^{-3}$?
  2. [1 point] How many numbers can be represented with 4 bytes?
  3. [1 point] Youtube previously represented view counts on videos with 4 bytes. What is the largest number of views that could be represented?
  4. [2 points] One more person viewed the video from 2.3? What would the view count be? What is this called?
  5. [3 points] We learned that we shouldn't compare floating point numbers with ==. Compare 0.75 and 3 / 4 in Python using == (even though we said we should not). Explain why it worked.

3. Booleans

  1. [4 points] Write an if statement that prints a variable if it has a magnitude less than 40, otherwise it prints 'Error, number is too large'. Demonstrate with your variable being -12.
  2. [2 points] Write an if statement that compares two variables to see if they're equal. Demonstrate this with two strings.

4. Lists

Use this list for the examples [3, 6, 1, 12, 43, 3, 100] and use only slicing to answer the questions.

  1. [2 points] Reverse the list
  2. [2 points] Print out every 3rd element starting from 6
  3. [2 points] Print out the first 4 elements.
  4. [2 points] Print out the last element using negative indexing
  5. [2 points] Print out all elements except the last one

5. List Functinos

[4 points] Using the len function, write a python expression that can print the second half of a list variable a. Your answer should be exactly 13 characters.