ISYS2047 –Information Systems Solutions and Design¶
Semester 2 2019¶
Assignment 1¶
Due date: Week 5¶
Submission¶
You should submit your assignment (.ipynb file) to Canvas before the start of your week 5 tutorial. You will then need to demonstrate your assignment in class to your tutor before the end of your week 5 tutorial.
Enter your name and student number in the cell below¶
Name: [ENTER YOUR FULLNAME]
Student number: [ENTER YOUR STUDENT NUMBER]
Question 1 (10 marks)¶
Given the product defined as product_104 in the cell below, write python code to perform the following:
• Print the value of the “product_category” key
• Insert a “product_sub_category” key and set its value to “Monitors”
• Remove the “lead_time_days” key
• Change the value of the “discontinued” key to 1.
Notes:
• Everytime you perform an operation, print the variable(s) to get some evidence that it worked
• And print a blank line (e.g. print()) to get a blank line beween the values printed
Hints:
• Week 2 Lecture notes and Lab Task 2.1 – Data Type: Collections
In [ ]:
product_104 = {
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Personal Computers”,
“product_description”: “8 inch Display (1920×1200) …”,
“product_id”: 104,
“product_name”: “NVIDIA SHIELD Tablet (WiFi)”,
“reorder_level”: 10,
“unit_price”: 299.0
}
# Write your code here
Question 2 (10 marks)¶
Given a list of products, defined as products in the cell below, write python code to perform the following:
For all discontinued products (i.e. discontinued = 1):
• Print the product_id on one line
• On another line print their product_category together with their product_description formatted as “product_category – product_description”
• A blank line should be printed between successive products
Notes:
• You MUST use a loop and a conditional statement.
• Hardcoding the answer (i.e. manually computing the answers) will result in no mark for this question. The answer must be “programmed” using a loop and a conditional statement.
Hints:
• Week 2 Lecture notes (lists, dictionaries), Week 3 Lecture notes (loops and conditional statements) and Lab Task 3.1 – Programming Constructs (loops and conditional statements).
In [ ]:
products = [
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Toy”,
“product_description”: “Pull out a bock without crashing the stack …”,
“product_id”: 101,
“product_name”: “Jenga Classic Game”,
“reorder_level”: 50,
“unit_price”: 14.99
},
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 2.5 inches Camera: 2 MP Talk Time: 4.5 hours Weight: 3.3 ounces”,
“product_id”: 102,
“product_name”: “AT&T Z431 GoPhone (AT&T)”,
“reorder_level”: 14,
“unit_price”: 49.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 4.5-inches Camera: 5-MP Input: Touchscreen OS: Android”,
“product_id”: 103,
“product_name”: “AT&T Z998 LTE Android Go Phone (AT&T Prepaid)”,
“reorder_level”: 29,
“unit_price”: 159.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Personal Computers”,
“product_description”: “8 inch Display (1920×1200) …”,
“product_id”: 104,
“product_name”: “NVIDIA SHIELD Tablet (WiFi)”,
“reorder_level”: 10,
“unit_price”: 299.0
}
]
# Write your code here
Question 3 (10 marks)¶
In the cell below, write code to process the given list of products to generate a dictionary.
The keys of the dictionary should be the “product_category” in the list and the values the count of products with that particular category.
After processing the list, the resulting dictionary should be: {‘Toy’: 1, ‘Wireless Phone Accessory’: 2, ‘Personal Computers’: 1}
One potential algorithm to implement the code is:
• Instantiate a blank dictionary e.g. “category_dict”
• Loop through the list of products
▪ Check if the “product_category” key of the product is in “category_dict”
◦ If no, insert the value of “product_category” key as a key in “category_dict” and set its value to 1
◦ If yes, increment the value of the key in “category_dict” by 1
Notes:
• You MUST use a loop and a conditional statement.
• Hardcoding the answer (i.e. manually computing the answers) will result in no mark for this question. The answer must be “programmed” using a loop and a conditional statement.
• Do not use “Counter” to implement the solution
• Your code should work for any number of “product_category”, not just the 3 “product_category” in the list given below.
• Hardcoding the answer will be penalised.
• This is probably the hardest question in the assignment!
Hints:
• Week 2 Lecture notes (lists, dictionaries), Week 3 Lecture notes (loops and conditional statements) and Lab Task 3.1 – Programming Constructs (loops and conditional statements).
In [ ]:
products = [
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Toy”,
“product_description”: “Pull out a bock without crashing the stack …”,
“product_id”: 101,
“product_name”: “Jenga Classic Game”,
“reorder_level”: 50,
“unit_price”: 14.99
},
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 2.5 inches Camera: 2 MP Talk Time: 4.5 hours Weight: 3.3 ounces”,
“product_id”: 102,
“product_name”: “AT&T Z431 GoPhone (AT&T)”,
“reorder_level”: 14,
“unit_price”: 49.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 4.5-inches Camera: 5-MP Input: Touchscreen OS: Android”,
“product_id”: 103,
“product_name”: “AT&T Z998 LTE Android Go Phone (AT&T Prepaid)”,
“reorder_level”: 29,
“unit_price”: 159.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Personal Computers”,
“product_description”: “8 inch Display (1920×1200) …”,
“product_id”: 104,
“product_name”: “NVIDIA SHIELD Tablet (WiFi)”,
“reorder_level”: 10,
“unit_price”: 299.0
}
]
# Write your code here
Question 4 (10 marks)¶
Given the list of products defined in the cell below, process the list of dictionaries to create a list of “product_id”.
Join the “product_id” with a comma followed by space to form a single string e.g. 101, 102, 103, 104 and print the string.
Notes:
• When adding “product_id” items to the list, you will probably need to cast them to strings in order to be able to join them later.
• Hardcoding the answer will be penalised.
Hints:
• Week 2 Lecture notes (lists, dictionaries), Week 3 Lecture notes (loops and conditional statements), Lab Task 3.1 – Programming Constructs (loops and conditional statements) and Lab Task 3.4 – Advanced Techniques for Collections (joining items in a list as a single string)
In [ ]:
products = [
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Toy”,
“product_description”: “Pull out a bock without crashing the stack …”,
“product_id”: 101,
“product_name”: “Jenga Classic Game”,
“reorder_level”: 50,
“unit_price”: 14.99
},
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 2.5 inches Camera: 2 MP Talk Time: 4.5 hours Weight: 3.3 ounces”,
“product_id”: 102,
“product_name”: “AT&T Z431 GoPhone (AT&T)”,
“reorder_level”: 14,
“unit_price”: 49.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 4.5-inches Camera: 5-MP Input: Touchscreen OS: Android”,
“product_id”: 103,
“product_name”: “AT&T Z998 LTE Android Go Phone (AT&T Prepaid)”,
“reorder_level”: 29,
“unit_price”: 159.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Personal Computers”,
“product_description”: “8 inch Display (1920×1200) …”,
“product_id”: 104,
“product_name”: “NVIDIA SHIELD Tablet (WiFi)”,
“reorder_level”: 10,
“unit_price”: 299.0
}
]
# Write your code here
Question 5 (10 marks)¶
In the cell below, write python code to create a dictionary named “emp_151” with the following key/value pairs:
• employee_id: 151
• email: “megan7218.underwood@gmail.com”
• firstname: “Megan”
• lastname: “Underwood”
• title: “Mrs”
• work_phone: “(07) 8608 2756″
Print the dictionary
Notes:
• This is probably the easiest question in the assignment
Hints:
• Week 2 Lecture notes and Lab Task 2.1 – Data Type: Collections
In [ ]:
# Write your code here
Question 6 (10 marks)¶
Given the list of products defined in the cell below, process the list of dictionaries to create a new list of dictionaries.
Only include products that are non-discontinued (discontinued=0) with unit_price greater than 15.0 in the new list.
Notes:
• This problem can be solved in one line using filter() with a lambda funtion
Hints:
• Lab Task 3.4 – Advanced Techniques for Collections
In [ ]:
products = [
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Toy”,
“product_description”: “Pull out a bock without crashing the stack …”,
“product_id”: 101,
“product_name”: “Jenga Classic Game”,
“reorder_level”: 50,
“unit_price”: 14.99
},
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 2.5 inches Camera: 2 MP Talk Time: 4.5 hours Weight: 3.3 ounces”,
“product_id”: 102,
“product_name”: “AT&T Z431 GoPhone (AT&T)”,
“reorder_level”: 14,
“unit_price”: 49.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 4.5-inches Camera: 5-MP Input: Touchscreen OS: Android”,
“product_id”: 103,
“product_name”: “AT&T Z998 LTE Android Go Phone (AT&T Prepaid)”,
“reorder_level”: 29,
“unit_price”: 159.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Personal Computers”,
“product_description”: “8 inch Display (1920×1200) …”,
“product_id”: 104,
“product_name”: “NVIDIA SHIELD Tablet (WiFi)”,
“reorder_level”: 10,
“unit_price”: 299.0
}
]
# Write your code here
Question 7 (10 marks)¶
Given the list of products defined in the cell below, process the list of dictionaries to create a list of product names formatted as product_id product_description unit_price e.g. 101 – Pull out a bock without crashing the stack … – 14.99, etc
Notes:
• This problem can be solved in one line using map() with a lambda function
• The output can be obtained using string concatenation
• Since product_id and unit_price are numbers, they will need to be cast to strings in order to be able to concatenate them
Hints:
• Lab Task 3.4 – Advanced Techniques for Collections
In [ ]:
products = [
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Toy”,
“product_description”: “Pull out a bock without crashing the stack …”,
“product_id”: 101,
“product_name”: “Jenga Classic Game”,
“reorder_level”: 50,
“unit_price”: 14.99
},
{
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 2.5 inches Camera: 2 MP Talk Time: 4.5 hours Weight: 3.3 ounces”,
“product_id”: 102,
“product_name”: “AT&T Z431 GoPhone (AT&T)”,
“reorder_level”: 14,
“unit_price”: 49.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Wireless Phone Accessory”,
“product_description”: “Display: 4.5-inches Camera: 5-MP Input: Touchscreen OS: Android”,
“product_id”: 103,
“product_name”: “AT&T Z998 LTE Android Go Phone (AT&T Prepaid)”,
“reorder_level”: 29,
“unit_price”: 159.99
},
{
“discontinued”: 1,
“lead_time_days”: 4,
“product_category”: “Personal Computers”,
“product_description”: “8 inch Display (1920×1200) …”,
“product_id”: 104,
“product_name”: “NVIDIA SHIELD Tablet (WiFi)”,
“reorder_level”: 10,
“unit_price”: 299.0
}
]
# Write your code here
Question 8 (10 marks)¶
Write Python code in the cell below to do the following:
• Calculate (and print) the number of days in semester 2 2019. Assume that the semester starts on Monday of week 1 and finishes on Friday of week 12.
• Print the start date of the semester in “dd/mm/yyyy” format
• Print the end date of the semester in “dd/mm/yyyy” format
Hint:
• Lab Task 2.3 – Data Type: Date and Datetime
In [ ]:
# Write your code here
Question 9 (10 marks)¶
We have some email addresses in the username\@universityname.edu.countrycode format.
User names, univeristy names and country codes are composed of letters only.
Write a program to print the user name, the university name and the country code of a given email address on seperate lines.
Example: If the email address is: james@rmit.edu.au, then, the following should be printed:
james
rmit
au
Hint:
• Lab Task 3.5 – Regular Expressions
• Use a regular expression, \w to match letters and group() to access the required values
In [ ]:
# Write your code here
Question 10 (10 marks)¶
In the cell below, write a class to represent a Product as per following specifications:
• Class name: Product (note uppercase “P”)
• Define instance attributes as specified by the items in dictionary object product2 i.e. discontinued, lead_time_days, etc.
• Define an __init__() method which initialises the instance attributes to the value of the parameters passed to the method
• Define a set_product_name() method which sets the product_name in the instance variable to the value of the parameter passed
• Define a get_product_details() method which returns the product details formatted as “product_name – product_description”
After having defined the class, you need to test the class and its methods to show that it works. You can do this as follows:
• Instantiate an object of the class (name it prod) and pass product2 to the initialiser (pass the whole product2 object, not individual attributes)
• Set the product_name to something different by calling set_product_name() and passing it an appropriate parameter
• Call get_product_details() to get the product name and description (and print it)
Hint:
• Lab Task 4.1 – Implement a class and Week 4 Lecture notes
In [ ]:
product2 = {
“discontinued”: 0,
“lead_time_days”: 4,
“product_category”: “Personal Computers”,
“product_description”: “8 inch Display (1920×1200) …”,
“product_id”: 104,
“product_name”: “NVIDIA SHIELD Tablet (WiFi)”,
“reorder_level”: 10,
“unit_price”: 299.0
}
# Write your code here
© France and Christopher Cheong 2019¶