Homework Assignment 1

Basic Expressions in Python


CS 1510
Introduction to Computing
Fall Semester 2014


Due: Thursday, September 4, at 8:00 AM


Introduction

This assignment gives you your first chance this semester to write Python expressions on your own and practice using the Python shell to evaluate them. As we saw in Lab 1, IDLE and its Python shell are our default environment for the course.

You may work on your own computer if you have installed IDLE there. Otherwise, you can work in any of the CHAS CS labs 112 Wright (when class is not in session), 339 Wright, and 335 ITTC. You log on to all the computers in these labs using your CatID.

Learning a programming language involves learning its tools. Be sure to spend plenty of time and energy familiarizing yourself with the shell, the editor, and its help system. Time invested now will pay big dividends later on!

As we go through the course, you will occasionally wonder to yourself, I wonder how I do <x> in IDLE? Fire up IDLE and see if you can find the answer. If you can't, please ask, and I'll try to find an answer. I will post answers to common questions on the course resources page.



Mechanics

For each of the following tasks, do the following:

At the end of the exercise, save the results of your shell window to a text file using the File | Save menu we saw in Lab 1. Name your file interactions.py.

As you work through the problems, record any predictions you are asked to make in a text file named homework01.txt. After you complete all the problems, add at least one question you have about Python at this point. You may, of course, ask more than one!

Save both of these files on your USB drive, as you did for Lab 1.



The Assignment

  1. What is the value of each of these expressions?
         3 * 12 - 5
         3 * (12 - 5)
         10 - 8 - 6 - 4
         (5 * 20) // 40 
         (5 * 20) % 40 
         (0.01 * 20) + (4 / -3)
    

    Make sure you understand why each result is what it is.


  2. Assume that the following names have been defined, in the given order:
         big_number = 10500900
         small_number = 0.00000025
         indiana = "hoosiers"
         number1 = big-number
         number2 = "big-number"
    
  3. What is the value of each of these expressions?

         big_number
         small_number
         "big_number"
         indiana
         "indiana"
         number1
         number2
         "number1"
    

    Use the Python shell to help you determine the answers.


  4. Consider this sequence of Python statements:
         my_int = 5
         my_int = my_int + 3
         print(my_int)
    

    Predict what will be printed after evaluating each statement in order. Then evaluate them in order in the Python shell. If your prediction did not match the result, figure out why.


  5. Simple interest on a loan is calculated as the product of:
    1. the principal, the amount borrowed,
    2. the term, the number of years to repay, and
    3. the interest rate.

    Write an expression to calculate the simple interest on $5,000 borrowed for a term of three years at 5.625%.


  6. Give an expression to compute the value of one of the roots of the equation
         3x2 + 17x - 12 = 0
    

    Yes, you need to use the quadratic formula! Python does not have a "built in" square root function, but sqrt() is defined in the math module. You can access it in the same way we accessed pi in Lab 1: import the math module, then use the full name math.sqrt.



Deliverables

By the due date and time, submit:

Use the on-line submission system. Recall the steps from Lab 1:

Don't forget to include your question...



Eugene Wallingford ..... wallingf@cs.uni.edu ..... August 29, 2014