IE 555 - Programming For Analytics

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

IE 555 – Programming for Analytics

Homework #3 – Writing a Python Function

Due: The next class period after we finish the first set of notes.
(Exact date will be announced in class)

The purpose of this assignment is to help you gain experience writing Python functions.

Assignment Details

You are asked to write a single Python function named myFunction. This function should be saved
within a file named UPPERCASEUBUSERID homework 3.py, you should replace UPPERCASEUBUSERID
with your UB username in ALL CAPS.

The myFunction function will expect 6 input arguments, in the form


myFunction(a, b, c, d, e, f).
The inputs are defined as follows:

• a – a string;
• b – a non-negative integer;
• c – a non-negative number (could be int or float);
• d – a single-dimensional list;
• e – a string, int, or float;
• f – a string representing a filename for a .csv file that will be saved in the same directory
(folder) as your .py script.

Your function should return (output) the following information, in this order:

• The b√th character of string a (i.e., a string of size or length 1).


• c2 + c + dce, rounded to 4 decimal places (i.e., a float value).
• How many times does the value of input parameter e appear in input list d? (This will be an
integer value.)
• How many rows and columns are in the file with the name provided by input variable f?
(This should be a list of the form [rows, cols].)

1
Example Function Inputs/Outputs

As an example, suppose someone calls your myFunction function via a Python terminal as follows:

1 >>> import U P P E R C A S E U B U S E R I D _ h o m e w o r k _ 3 as hw3


2 >>> response = hw3 . myFunction ( ’ qrstuvwxy ’ , 3 , 2.7 , \
3 [9 , ’a ’ , 3.14 , ’a ’ , 9] , ’a ’ , ’ practice . csv ’)
4 >>> print response
5 ( ’s ’ , 11.9332 , 2 , [5 , 3])
6 >>> response [0]
7 ’s ’
8 >>> response [1]
9 11.9332
10 >>> response [2]
11 2
12 >>> response [3]
13 [5 , 3]

The file practice.csv has been provided in GitHub.

NOTE: You should experiment with using different inputs to verify that your code works properly.

Grading
• If you correctly submit your homework by the due date, you will have earned 100 points (the
maximum score) on this assignment.
• The TA will notify you if your submission has any errors. In such a case, you will need to
re-submit your assignment.
– Each re-submission of your assignment will result in a 10-point deduction.

Submitting Your Assignment

Send an email, with a subject of “IE 555 Homework 3”, to the course TA (Hadi Feyzollahi,
hadifeyz@buffalo.edu). Be sure to include your UPPERCASEUBUSERID homework 3.py file as an
attachment.

You might also like