Microsoft Word - Assignment 2.docx
Assignment 2
Data management system – ToDo Application
Due: August 22 end of the day (no extensions)
In this assignment you will be required to use both files and database.
Your goal is to create application that satisfies the following requirements:
1. Application is written in a single Python script called assignment2.py
2. Application, upon start reads a file named config.txt that contains a single line with the
name of the database file
3. Application gracefully handles e
or situations such as:
a. Missing config file/Inco
ect name of the config file
. Missing database file/Inco
ect name of the file
4. Application allows user to add and remove items to the ToDo list
5. Item should have the following attributes:
a. ID (Primary key)
. Title (text, not null)
6. Application should provide menu (console) allowing user to perform following
operations:
a. Show all items sorted by ID
. Delete selected item by ID
c. Add new item
d. Exit the application
Marking scheme:
1. Reading file: 1 point
2. Opening database: 1 point
3. Select statement: 2 points
4. Delete statement: 2 points
5. Handling exceptions: 3 points (file, db access, db que
ies)
6. App UI 2 points
class1-svsbmlzj.zip
class1.py
Przemyslaw Pawluk
4:46 PM
class Item:
def __init__(self, prod="", quantity=0, note=""):
self.__product = prod
self.__quantity = quantity
self.__note = note
@property
def quantity(self):
return self.__quantity
@quantity.sette
def quantity(self, value):
if(value>0):
self.__quantity = value
def __str__(self):
return self.__product+"\t"+str(self.__quantity)+"\t"+self.__note
class ShopingList:
def __init__(self):
self.mylist = []
def addItem(self, item):
if(isinstance(item, Item)):
self.mylist.append(item)
def __str__(self):
s = ""
if len(self.mylist)==0:
return "EMPTY"
for i in self.mylist:
s=s+"\n"+str(i)
return s
sList = ShopingList()
def showList():
global sList
print(sList)
def addElement():
global sList
name = input("Enter product name:")
qunat = int(input("Enter product quantity (integer)"))
note = input("Enter note for the product")
i = Item(name, qunat, note)
sList.addItem(i)
print("Item was added successfully")
def printMenu():
print("Select your option:")
print("1. Show list")
print("2. Add item")
print("3. Remove item")
print("4. Remove all items")
print("5. Exit")
if __name__=="__main__":
selection = 7
while not selection == 5:
printMenu()
selection = input()
selection = int(selection)
if selection==1:
showList()
elif selection==2:
addElement()
print("Bye!")
class-hegunprv.zip
class.py
class 😄
commonName = "C"
def __init__(self, name="John Doe", number="0"):
self.__name = name
self.__number = numbe
@property
def name(self):
return self.__name
@name.sette
def name(self, value):
self.__name = value
@property
def number(self):
return self.__numbe
@number.sette
def number(self, value):
self.__number = value
def setName(self,name):
self.__name = name
def getName(self):
return self.__name
def __str__(self):
return "class 😄 name="+self.__name+", number="+self.numbe
def __eq__(self, other):
if(isinstance(other, C)):
return self.__name==other.__name and self.number==other.numbe
return False
def callNumber(self):
pass
o1 = C("Smith")
o2 = C("Smith")
o3 = o1
print(o1)
print(o2)
o1.commonName = "ZZZ"
C.commonName = "DDD"
print(o1.commonName)
print(o2.commonName)
print(o3.commonName)
o1.name = "Tom"
print(o1.name, o1.number)
lab61-j3
nnah.zip
lab6(1).py
def is_winning_row(board, row_num, player):
''' (str, int, str) -> bool
board: a tic-tac-toe board represented as a string
row_num: an integer from 0 to 2
player: a single character string, "X" or "O"
returns True if and only if the player character is fills the row row_num.
is_winning_row("XXXO O ", 0, "X")
True
is_winning_row("XOXOXOXOX", 1, "X")
False
'''
pass # Remove this line and write your code
def eval_poly(p, v):
''' (list, int) -> int
Computes the value of the polynomial p(x) for x=v.
eval_poly([3,0,-1,2],1)
4
'''
pass # Remove this line and write your code
def is_permutation(p):
''' (dict) -> bool
Returns True if and only if p represents a permutation as described in the handout.
Specifically, p maps a collection of objects to the same collection of objects, with the
additional condition that different objects are mapped to different values.
If you have well abso
ed the concepts taught so far, the body of your function should
contain no more than one line of code.
is_permutation({'a': 'b', 'b': 'c', 'c': 'a'})
True
is_permutation({1: 1, 2: 3})
False
'''
pass # Remove this line and write your code
def process_order(shipping, order):
''' (dict, tuple) -> NoneType
shipping: a dictionary where key is a string, and values are dictionaries
order: a tuple of the form (string, string, int)
The function returns no value. It rather mutates the shipping dictionary to
include the order in the co
ect position.
shipping = {}
process_order(shipping, ("Toronto", "apples", 100))
shipping == {'Toronto': {'apples': 100}}
True
process_order(shipping, ("Montreal", "apples", 200))
shipping == {'Toronto': {'apples': 100}, 'Montreal': {'apples': 200}}
True
process_order(shipping, ("Toronto", "apples", 200))
shipping == {'Toronto': {'apples': 300}, 'Montreal': {'apples': 200}}
True
'''
pass # Remove this line and write your code
lab5-dmutku0d.zip
Lab5/lab5-1.py
"""
Type your name and student ID below.
Name (as it appears on Blackboard): Kashyap Gauswami
Student ID:
If either name or student ID is missing or inco
ect, your grade will be set automatically to zero.
"""
def hash(s, c=0, useC=False):
"""
:param: s: non-empty string
:param: c: a multiplier used to calculate hash if useC is true
:param: useC: a bool value that decides if we use c
return: an int that is a sum of numerical values of all characters from the string s
XXXXXXXXXXmultiplied by c if useC is true or simply a sum when it is false
hash("test")
448
hash("test", 2, True)
896
"""
# Hint: use function ord() to get numerical value of the character.
answer = 0
#for i in range(s.length()):
for i in range(len(s)):
#if(not useC):
XXXXXXXXXXif (useC):
#answer = answer + c * ord(S[i])
XXXXXXXXXXanswer = answer + c * ord(s[i])
XXXXXXXXXXelse:
XXXXXXXXXXanswer = answer + ord(s[i])
return answe
def sum(n):
"""
:param n: a non-negative intege
:return: sum of odd numbers less or equal n XXXXXXXXXX+...
sum(6)
9
"""
if(n>=0):
XXXXXXXXXXanswer = 0
XXXXXXXXXXfor i in range(n):
XXXXXXXXXXif(i%2 != 0):
XXXXXXXXXXanswer = answer + i
return answe
def wighted_average(grades, weights):
"""
:param: grades: a
ay of non-negative ints
:param: weights: a
ay of tuples that contains weight as int representing percentages (0-100)
XXXXXXXXXXand int representing max number of points e.g. (10, 20)
:return: a weighted average calculated as a sum of (grade/max)*weight
Example, [10,100,5], [(30,10), (50,100), (20,5)]
wighted_average([10,100,5], [(30,10), (50,100), (20,5)])
XXXXXXXXXX
wighted_average([5,50,5], [(30,10)