CS2316 SPRING 2021 HOMEWORK 01: PYTHON REVIEW AND OOPPurposeUsing object-oriented programming (OOP) when writing code reduces development timebecause you can reuse code and develop models based on previous objects. Objects alsoseparate themselves to prevent accidental overwriting or influence from other programs. Agood understanding of OOP basics, design principles, and
...[Show More]
CS2316 SPRING 2021 HOMEWORK 01: PYTHON REVIEW AND OOP
Purpose
Using object-oriented programming (OOP) when writing code reduces development time
because you can reuse code and develop models based on previous objects. Objects also
separate themselves to prevent accidental overwriting or influence from other programs. A
good understanding of OOP basics, design principles, and design patterns will help
programmers develop well-written, reusable code.
Skills
This assignment will give you practice with object oriented programming concepts. You
will learn to write completely new classes and also create instances of those classes. You
will learn how objects interact with each other, and improve your skills at determining
which methods work with which types of objects.
Knowledge
You will gain knowledge in how to develop a new class and how to use objects that are of
that class. Using methods from other classes will help you understand the underlying
structure of a class. Understanding class structure will be helpful not only in developing
new classes, but in using existing classes more efficiently.
Important
1. Due Date: 02/10/2021 at 11:59 pm
2. This homework is graded out of 100 points.
3. This is an individual assignment. You may collaborate with other students in this
class. Collaboration means talking through problems, assisting with debugging,
explaining a concept, etc. Students may only collaborate with fellow students
currently taking CS 2316, the TA's and the lecturer. You should not exchange code or
write code for others. For individual assignments, each student must turn in a unique
program. Your submission must not be substantially similar to another student's
submission. Collaboration at a reasonable level will not result in substantially similar
code.
4. For Help:
○ TA Helpdesk / Ed Discussion Board
○ Python Fundamentals Handout, OOP Handout
○ http://openbookproject.net/thinkcs/python/english3e/
5. Comment out or delete all your function calls. Only global variables, and comments
are okay to be outside the scope of a function. When your code is run, all it should do
is run without any errors.
6. Do not wait until the last minute to do this assignment in case you run into problems.
7. Read the entire specifications document before starting this assignment.
8. IF YOUR CODE CANNOT RUN BECAUSE OF AN ERROR, IT IS A 0%
CS2316 SPRING 2021 HOMEWORK 01: PYTHON REVIEW AND OOP
Introduction
The goal of this homework is to showcase your knowledge of Python techniques, including
comprehensions and Object-Oriented Programming (OOP). You should test your classes
and methods out first on your own computer. Then when you have one or more of them
working, upload the entire file (which must be named HW01.py) to GradeScope to see how
well your code performs on the test cases we have created. You can submit the homework
file as many times as you'd like before the deadline.
Make sure you write your code in the template we provided to you (HW01.py) and follow
the formatting requirements for one line functions.
One-line Formatting
Correct:
Correct:
Incorrect:
Incorrect:
def function_a(param1):
return [i for i in param1]
def function_a(param1):
return type(param1)
def function_a(param1):
val = [i for i in param1]
return val
def function_a(param1):
return helper(param1)
def helper(param1):
return [i for i in param1]
CS2316 SPRING 2021 HOMEWORK 01: PYTHON REVIEW AND OOP
Functions and Classes
A grading rubric including point distribution is provided at the end of this document.
Part 1: Functions
Function name: add_floats
Parameter(s): num_list ( list )
Return Type: float
Description: Write a function that passes in num_list, a list of floats, ints, or strings
representing numbers, and returns a float of all valid numbers added together. A valid
number is any non-whole number (e.g. 5.0 is not valid despite being a floating point
number). You may assume that there will be at least 1 valid number in num_list. You will
have to convert some values into floats.
Python Test Cases:
Function name: string_modifier
Parameter(s): str_list ( list )
Return Type: list
Description: Write a function that passes in str_list, a list of strings containing any
alphanumeric characters, and returns a list of the strings multiplied by their index in the
list. Your returned list should only contain the strings that were originally made up of only
letters. You may assume the strings in str_list will be in lowercase. Hint: .isalpha()
may be helpful.
Python Test Cases:
>>> num_list = [1, 3.2, '2.8', '3']
>>> add_floats(num_list)
6.0
>>> num_list = [2.0, 3.5, '9', 8.1]
>>> add_floats(num_list)
11.6
>>> str_list = ['a', 'b', 'c', '4d']
>>> string_modifier(str_list)
['', 'b', 'cc']
[Show Less]