COSC 101 Homework 1: Fall 2024

The due date for this homework is Thursday, Sep 12 at 11:59PM.

Introduction

This assignment is designed to give you a first introduction to writing programs in Python! By completing this assignment, you will demonstrate that you understand a number of important concepts:

Important Tips

Your assignment

Your task is to complete following steps:

  1. Download the hw1.zip file from the course website and open it. You will see two python files, hw1_types.py and hw1_madlibs.py, in the unzipped folder. You are expected to write your programs in these files.
  2. Review the criteria used in Grading
  3. Complete hw1_types.py. This file is used in Task 1.
  4. Complete hw1_madlibs.py. This file is used in Task 2.
  5. Complete your trip_plan. This file is from Task 3.
  6. Submit your completed work.

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.

Grading

When we are assessing your code, higher levels of achievement are demonstrated, in part, by

Task 1

Types and Casting Description

In the hw1_types.py file, you will find that the main function contains several variables that are already defined. This is starter code, which is provided to assist you for the relevant task. Starter code will be denoted by comments and instructions as to whether the provided code should be modified or not. For this task (and all those in this homework), do not modify the starter code. You should write your code below the starter code (as indicated in the file).

Your task is to:

  1. Write code to print the type of each of the existing variables in the same order in which they were assigned.

  2. Write code convert the value of r to a float, raise it to the power of u, and display the type of the result, without modifying the values of any of the variables.

  3. Update the variable q to be the remainder when t is divided by u.

  4. Print the new value of the variable q.

  5. Print the value of the variable s

  6. Write code make a new variable z which contains the value'hi43hi43hi43' by only using basic operators and the variables.

  7. Print the value of the variable z.

The full output of your program should be exactly equivalent to the following:

<class 'str'>
<class 'str'>
<class 'str'>
<class 'int'>
<class 'int'>
<class 'float'>
1
hi
hi43hi43hi43

Task 2

Madlibs Description

In the hw1_madlibs.py file, write a short program that asks for a noun (string) and two verbs (both strings). (The verbs should be third person singular). Using the three inputs, your program should print the sentence:

If it <verb 1> like a <noun> and <verb 2> like a <noun>, it probably is a <noun>.

Here is an example run of the program:

What's the noun? cat
What's the first verb? sleeps
What's the second verb? eats
If it sleeps like a cat and eats like a cat, it probably is a cat.

Here’s another example:

What's the noun? river
What's the first verb? flows
What's the second verb? bubbles
If it flows like a river and bubbles like a river, it probably is a river.

Task 3

Grocery Trip Description

The semester has just started and you are already tired of the dinning hall food. You and your friends would like to know how much time it takes to drive to a grocery store. Oddly, you can only measure distance in feet.

In this task, you should sketch out either by hand on paper or on a whiteboard (make sure to take a picture) an algorithm that helps you plan your trip. Your algorithm should ask for a driver’s name, the distance (in feet), and the speed (in miles per hour). It should calculate and report how long it will take for the driver to arrive at the destination. The time should be reported in units of days, hours, minutes, and seconds (rounding to the nearest second).

Your sketch should not be python code. Rather, it should describe the logic and steps needed to accomplish the task, drawing on the computational thinking you have demonstrated in lab and in class.

The following are some examples to demonstrate what your algorithm should output.

Fig is hungry. Price Chopper is roughly 14,446 feet from Colgate. You are driving in the town, so your average speed will be 31 mph. Your program’s output should look like this:

Who will be driving? Fig
How far away is the destination (in feet)? 14446
How fast will fig be driving on average (in mph)? 31
It will take fig 0 days 0 hours 5 minutes and 18 seconds.

Luiz is willing to drive you all to Asia Food Market. The distance between Colgate and Asia Food Market is roughly 204,431 feet and Luiz will be driving at 30 mph (he is new to driving and nervous). Your program’s output should look like this:

Who will be driving? Luiz
How far away is the destination (in feet)? 204431
How fast will Luiz be driving on average (in mph)? 30
It will take Luiz 0 days 1 hours 17 minutes and 26 seconds.

Aditi will be driving you all to Pike Place Fish Market in Seattle. The distance is roughly 14,691,600 feet, and Aditi will be driving at 75 mph on average. Your program’s output should look like this:

Who will be driving? Aditi
How far away is the destination (in feet)? 14691600
How fast will Aditi be driving on average (in mph)? 75
It will take Aditi 1 days 13 hours 6 minutes and 0 seconds.

Submission Instructions

Submit two Python files and your trip_plan to the platform indicated in your class section:

Remember to complete the questions at the top of each file before submitting.