﻿

## Homework 1 (due 4/9) CSC 241

We started with a short introduction to computer science (see Chapter 1, and the presentation slides on d2l). We then moved on to Python, and saw how to write Python using the IDLE interface (both in the shell, and programs). The code we've written so far has focussed on basic arithmetical expressions (Section 2.1 of the book), variables, functions, input/output, the math library, and some simple Boolean expressions (see Sections 2.5 and 3.1). Next week we will talk more about Boolean expressions, types of values (integers, floats, strings).

Also of interest:

Submission: The homework is due by midnight (I will not accept late homeworks). You can submit your homework through d2l into the drop-box for this homework.

Please prepare your homework as a single file containing all answers (e.g. doc, docx, or pdf, not a zip file). When submitting programs, include the programs, together with screenshots of test-runs of your program (make sure screenshots are sized so the text is legible; resize and/or crop the images). For an example, see hwexample.docx . How to take screenshots? Check out screenshots for MAC, Windows, Linux. Unless I ask for it specifically, you do not have to submit separate files with program code or executables. If multiple files are necessary, please do not zip them up, just submit them separately.

1. (Reading Assignment) Read Chapter 1, 2.1, 2.5, and 3.1 of the textbook. If you want to read ahead, check out Sections 2.2, 2.3, and Chapter 3.

2. (Academic Integrity) Please read this academic integrity statement. Sign the document (electronically is fine), and submit it to the AI submission folder.

Note: For all of the following problems: do not use any features that we have not covered in class (unless explicitly asked to do so).

3. (Basic Expressions, 12pt) Write (and run) arithmetial expressions for the following tasks.

1. The sum of the numbers 1 to 10.

2. The product of the numbers 1 to 10.

3. Verify your answer from b) by using the factorial function from the math library. Hint: import the factorial function using "from math import factorial". factorial(n) is the product of the numbers from 1 to n.

4. (Expressions, 8pt) Write (and run) expressions for the following tasks (the expressions here are more important than the results, include your expressions).

1. Let's say an average movie file is around 7GB (Gigabyte; giga, in information technology, means 2 raised to the power 30). You just bought an external harddrive which can store 2TB (Terabyte, tera, in information technology, is 2 raised to the power 40, so a Terabyte is 1024 Gigabyte). How many movies can you store on your external harddrive? Write (and execute) a Python expression that calculates the integer value. Hint: don't worry about integer at first; then a small modification will give you the integer value.

2. Assuming you sotre as many movies as possible on your 2TB hardrive, and all movies require exactly 7GB, how many GB are left free at the end? Hint: again, be sure to show the expression that calculates this, not just the answer. You will need the expression from a.

5. (Variables in a Program, 10pt) Write a program that calculates the distance of a point (x,y,z) in 3D from the origin. The formula for the distance is (x2 + y2 + z2)0.5. So the same formula we saw in class, with an addition term for z. The program should use variables x, y, z which you set (by hand) before running the program. Here's the result of running the program with 3, 1, 7:

Also include a second test-run for values 4, 1, 8.

6. (Input/Output, 10pt) Write a program that prompts the user for a student's hw, midterm and final exam percentages, and calculates the class percentage based on that (with hw being worth 40%, and each exam 30%). Below are two test-runs.

Hint: First prompt the user for the inputs; then calcuate the score, finally print it. We saw a very similar example in class, which will serve as a good starting point.

7. (Extra Creedit, hard, 5pt) You have four variables with homework percentages: hw1. hw2. hw3, hw4. Write a single arithmeticcal expression (only using arithmetic and max/min) that calculates the average homework score if the lowest two homework scores are dropped. Note: this is trickier than you may think.

Marcus Schaefer
Last updated: April 3rd, 2019.