COSC 101 Homework 3: Fall 2023

The due date for this homework is Sunday, February 18, 11:00pm. Note, this is an extension on our typical Friday deadlines.

Introduction

This homework is designed to give you practice with the following topics:

As usual, we encourage you to start early.

Your assignment

Your task is to complete following steps:

  1. Download the hw3.zip file from the course website and open it. You will see three python files, hw3_racing.py, hw3_resizetower.py, and hw3_randompassword.py, in the unzipped folder. You are expected to write your programs in these files.
  2. Complete hw3_racing.py. This file is used in Part 1
  3. Complete hw3_resizetower.py. This file is used in Part 2
  4. Complete hw3_madlibs.py. This file is used in Part 3
  5. Review the grading criteria at the end of this assignment.
  6. (OPTIONAL) Do the challenge problem for this homework.
  7. Submit your completed programs.

Notice that each starter .py file has a header with some information for you to fill in. Please do so. Your feedback helps the instructors better understand your experiences doing the homeworks and where we can provide better assistance.

Part 1

Central New York Racing

You and your friends really enjoy the Fast and Furious movies and have started to race between Hamilton and Cazenovia (please don’t do this). You are tasked with writing a program to calculate and analyze driving times for this race. Given the times of a certain number of drivers (entered by the user), your program should perform the following tasks:

  1. Input the drive times (all the drive times are entered at once, on a single line and separated by |).
  2. Transform the drive times input from a |-separated string to a list of decimal values.
  3. Compute the average, fastest and slowest drive times. You must use the min and max built-in functions. You must NOT use the sum function. Instead, you must use the accumulator pattern in order to compute the average drive time.
  4. Print the stats computed at the previous step.

Example program output (25.5|28.0|23.0|22.9|27.6 is the input that the user enters):

Enter drive times (|-separated): 25.5|28.0|23.0|22.9|27.6
Average drive time: 25.40 seconds
Fastest drive: 22.90 seconds
Slowest drive: 28.00 seconds

Note: In hw3_racing.py we have provided you with a code structure and descriptions for each function. Make sure to read and follow these instructions. Add parameters and return values along with their corresponding type annotations wherever it’s needed. DO NOT modify the code structure (for example by adding or removing functions) before consulting with your instructor.

Part 2

Tower Resized

Continuing last week’s exploration of the Tower, we will now make a scalable version of the Tower. In other words, the art is not a fixed sequence of characters, but a pattern that can be drawn at a variety of scales. Visit Tower webpage to get a sense of how the tower must look at different scales.

Each program must ask the user for a positive number and then scale the text pattern accordingly.

Example program output (1 is the input entered by the user):

Specify the scale: 1
      ||
      ||
   __{{}}__
__{::::::::}__
||||||||||||||
(_)()()()()(_)
  (_)()()(_)
  ____][____
   ___][___
      ||
      ||
   |%%%%%%|
   |%%%%%%|
   |%%%%%%|
   |%%%%%%|
   __{{}}__
__{::::::::}__
||||||||||||||

Note: In hw3_resizetower.py we have provided you with a code structure and descriptions for each function. Make sure to read and follow these instructions. Add parameters and return values along with their corresponding type annotations wherever it’s needed. DO NOT modify the code structure (for example by adding or removing functions) before consulting with your instructor.

Part 3

Random Password

You recently got your online bank account hacked in a recent attack. In order to create a better password that isn’t just password123, you decide to create a random password generator to make sure your passwords are more secure. Write a Python program that generates random passwords for users based on their desired password length. The program should:

  1. Ask the user for the desired length of the password.
  2. Randomly select length number of characters from the string of all permitted characters (a mix of uppercase letters, lowercase letters, digits, and special characters).
  3. Print the password string.

Example program output (10 is the input entered by the user):

Enter the desired password length: 10
Generated password: fdj)6i%Kt6

Note: In hw3_randompassword.py we have provided you with a code structure and descriptions for each function. Make sure to read and follow these instructions. Add parameters and return values along with their corresponding type annotations wherever it’s needed. DO NOT modify the code structure (for example by adding or removing functions) before consulting with your instructor.

Grading

Your assignment will be graded on two criteria:

  1. Correctness [90%]: This document contains examples for each program. Be sure that you run your program once for each example and make sure it works correctly for each one! Then, run your code with additional examples of your choosing.

    The correctness part of your grade is broken down as follows:

    Category Portion of grade
    Part 1 30%
    Part 2 30%
    Part 3 30%
  1. Program design and style [10%]: style and program design become increasingly important the more complex your program becomes. For these first programs, adhere to the following guidelines:

Challenge Problem (OPTIONAL)

Challenge problems are entirely optional extensions to the homework. If you complete them successfully, you are rewarded with a sense of accomplishment and a small number of extra points on the homework. They are intended for students who want to explore a little further; only pursue the challenge problem after you have successfully completed the homework.

For this week, the challenge problem is to implement a scalable ascii art pattern of your choosing. For inspiration, you can take a look at the Wikipedia page on ASCII Art and the ASCII art archive.

If you choose to do the challenge problem, please write your code in a separate file called hw3_challenge.py. Have fun!