Homework 1 (due 4/5)
CSC 401



We covered basic expressions (arithmetical, Boolean), variables, different types of values (integers, floats, strings, basic functions (min, max), input and output (input, print) and the math library.  You'll find this material in sections 2.1-2.2, 2.5 and 3.1 of the book. Next week, we'll talk about lists (2.3), objects and types (2.4), and continue with Chapter 3 (Section 3.2-3.4).


Submission: The homework is due by end of day, midnight (I will not accept late homeworks). You can submit your homework through d2l into the drop-box for the 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 screenshots of both your code (program), 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 (hwexample.pdf). 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 2.1, 2.2, 2.5  and 3.1 of the textbook. Be sure to work through the practice problems, and check out (appopriate) end of chapter problems. If you want to read ahead for next time, read 2.3, 2.4, and Chapter 3.

2. (Arithmetical Expressions, 15pt) Write (and run) expressions for the following tasks. The expressions here are more important than the results, so be sure to include the expressions you used, not just the results.

  1. Let's say you've picked a password with 8 characters (where a character is either an upper or a lower case letter in the latin alphabet, so you have 52 choices for each character). How long would it take for a brute-force attack to break your password, that is, how many seconds does it take to try all possible passwords? You can assume that your attacker knows that your password consists of 8 upper/lower case letters, and that the attacker's computer can check one password every nanosecond (10-9 seconds). Note: the passwords need not be meaningful, so AyGGtpBx could be your password. In a first step, write an expressions to calculate the number of possible passwords. Then modify the expression to calculate the time it takes to try all passwords. Hint: How many passwords of length 1 are there? Length 2? ...

  2. To improve your security, you increase the length of your password to 12 characters. In that case, a brute-force attack will take roughly 390877006486 seconds. To get an idea of how long that is, re-express this in different units:

    • how many days are 390877006486 seconds?

    • how many years are 390877006486 seconds?

    • how many millenia are 390877006486 seconds?

    Hint: You can assume that a year is 365 days, and a millenium is 1000 years. Note: Include the expression you use for calculating your answer as well are your result.

  3. If your height is 180 centimeters, how many feet and inches is that? (You can assume that a foot is 12 inches, and an inch is 2.54 centimeters). Write two separate expressions, one for feet and one for the remaining inches. Here are some sample runs of the two expressions (with the actual expressions blacked out), so, for example, 180cm is 5ft 10in, as is 178cm, while 190cm is 6ft 2in. Note that the answers are integers, not floating point values. There are various ways in which you can do this, easiest way is to use the int() function (book page 37, alternatively, the math library offers a floor() function). Hint: Do the expression for feet first. You may have to reuse that in the expression for inches.

 3. (Numbers and Boolean expressions, 15pt) The following tasks will work with the class grading scheme (see class web-page). Write (and run) expressions for the following conditions:

  1. You are getting an A- in the class basec on your class percentage per. Note: the grading scheme lists a percentage of 90-95. Make the lower bound, 90, inclusive, and the upper bound, 95, exclusive (95 percent is an A).

  2. You are not getting an A- in the class, based on per.



    Hint
    : do a) first.

  3. You are getting a B+ or a C+

4. (A Short Program, 10pt) Write a short program that prompts the user for their first name, and then for their last name, and then prints a message of the form: 'So your name is ... ..., is it?', where ... and ... are first and last name as entered by the user. Below are two test-runs:

 

 

Hint: start by modifying the week1c.py program. Do first name first. Then add in last name.


Marcus Schaefer
Last updated: March 31st, 2017.