Not logged in. Login

Programming Assignment 0: Python warmup

In this assignment, we will go through some of the basic concepts of Python programming, and try to practice the primary coding skills used in the rest of the assignments. You can download all the scripts as a zip here.

This assignment requires that your computer has installed Python 3 with the numpy package.

Files you will edit:

EvenOdd.py
ShoppingCost.py 
FarmersIncome.py 

What to submit: You should modify and submit the Python codes as a single zip file.

Submit to https://coursys.sfu.ca/2019fa-cmpt-310-d1/+a0/submission/

Evaluation: Your code will be autograded for technical correctness. Please do not change the names of the files or any of the provided functions. Also, do not use any other module or library other than those imported by default (i.e. do not add any import statement to the code.) The correctness of your implementation -- not the autograder's output -- will be the final judge of your score. If necessary, we will review and grade assignments individually to ensure that you receive due credit for your work.

Academic Dishonesty: We will be checking your code against other submissions in the class for logical redundancy. We trust you all to submit your own work only; please don't let us down. If you do, we will pursue the strongest consequences available to us.

Getting Help: You are not alone! If you find yourself stuck on something, post on Piazza to ask for help. The TAs will also have additional office hours before the assignment is due. You can email the TAs with questions that are not appropriate for Piazza. We want these projects to be rewarding and instructional, not frustrating and demoralizing. But we don't know when or how to help unless you ask. One more piece of advice: if you don't know what a variable does or what kind of values it takes, print it out.

Question1: Even or Odd (2 points)

In this question, you will be asked to extract all the even numbers in a list of integers. If there is no even number in the list, then you should return an empty list.

For this question, after downloading the zip file, you are required to modify EvenOdd.py. You can run your code using:

python EvenOdd.py

Note: Make sure you are running a recent version of Python (3.6 or later). Depending on your system configuration, you may need to use "python3" instead of "python" on the command line to run this program.

Question2: Shopping prices (5 points)

You can find a Grocery.csv file in the downloaded zip. It contains two columns: the first column is a list of products and the second column indicates their price. a. In the function createPricesDict(), create a dictionary of each product mapped to its price. b. Suppose we have another dictionary for our cart items, mapping each product to its quantity. Complete the function calculateShoppingCost() to get this dictionary as well as the dictionary created in the previous step and return the total amount that the customer owes.

For this question, you are required to modify ShoppingCost.py. You can run your code using:

python ShoppingCost.py

Question3: Farmer's income (3 points)

Jack, Emma, and Brian are the only three farmers in their town who sell milk, butter, yogurt, and cheese. The table below shows the absolute amount of each product which is being sold monthly.

Milk(ltr) Butter(kg) Yogurt(kg) Cheese(kg)
Jack 600 200 400 300
Emma 100 700 300 200
Brian 300 100 300 500

For example, the first column lists that 600 liters of the milk produced comes from Jack’s farm, 100 liters from Emma’s farm, and 300 liters from Brian’s farm. The table is fixed for different months.

Now suppose that you are given four numbers indicating the monthly price of the milk, butter, yogurt, and cheese per unit respectively. For example, the first number will be the amount of money all three farmers have made from selling one litre of milk. Complete the function getMonthlyIncome() that given these four numbers as a list, calculates the monthly income of each farmer.

For this question, you are required to modify FarmersIncome.py. You can run your code using:

python FarmersIncome.py

Note: In this question, please use Numpy for matrix multiplication.

Feedback

Give one short piece of feedback about the course so far. What topics have you found it hard to understand? What topics are you most looking forward to? Also, please report the number of hours you spent on this assignment to help us calibrate the difficulty. Please provide your answers in the space provided in EvenOdd.py.

Updated Mon Sept. 09 2019, 11:27 by liuhengl.