Skip to content

Commit 1703827

Browse files
committed
COSI 127b PA2
0 parents  commit 1703827

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# COSI-127b-PA2
2+
# 加微信 powcoder
3+
4+
# [代做各类CS相关课程和程序语言](https://powcoder.com/)
5+
6+
[成功案例](https://powcoder.com/tag/成功案例/)
7+
8+
[java代写](https://powcoder.com/tag/java/) [c/c++代写](https://powcoder.com/tag/c/) [python代写](https://powcoder.com/tag/python/) [drracket代写](https://powcoder.com/tag/drracket/) [MIPS汇编代写](https://powcoder.com/tag/MIPS/) [matlab代写](https://powcoder.com/tag/matlab/) [R语言代写](https://powcoder.com/tag/r/) [javascript代写](https://powcoder.com/tag/javascript/)
9+
10+
[prolog代写](https://powcoder.com/tag/prolog/) [haskell代写](https://powcoder.com/tag/haskell/) [processing代写](https://powcoder.com/tag/processing/) [ruby代写](https://powcoder.com/tag/ruby/) [scheme代写](https://powcoder.com/tag/drracket/) [ocaml代写](https://powcoder.com/tag/ocaml/) [lisp代写](https://powcoder.com/tag/lisp/)
11+
12+
- [数据结构算法 data structure algorithm 代写](https://powcoder.com/category/data-structure-algorithm/)
13+
- [计算机网络 套接字编程 computer network socket programming 代写](https://powcoder.com/category/network-socket/)
14+
- [数据库 DB Database SQL 代写](https://powcoder.com/category/database-db-sql/)
15+
- [机器学习 machine learning 代写](https://powcoder.com/category/machine-learning/)
16+
- [编译器原理 Compiler 代写](https://powcoder.com/category/compiler/)
17+
- [操作系统OS(Operating System) 代写](https://powcoder.com/category/操作系统osoperating-system/)
18+
- [计算机图形学 Computer Graphics opengl webgl 代写](https://powcoder.com/category/computer-graphics-opengl-webgl/)
19+
- [人工智能 AI Artificial Intelligence 代写](https://powcoder.com/category/人工智能-ai-artificial-intelligence/)
20+
- [大数据 Hadoop Map Reduce Spark HBase 代写](https://powcoder.com/category/hadoop-map-reduce-spark-hbase/)
21+
- [系统编程 System programming 代写](https://powcoder.com/category/sys-programming/)
22+
- [网页应用 Web Application 代写](https://powcoder.com/category/web/)
23+
- [自然语言处理 NLP natural language processing 代写](https://powcoder.com/category/nlp/)
24+
- [计算机体系结构 Computer Architecture 代写](https://powcoder.com/category/computer-architecture/)
25+
- [计算机安全密码学computer security cryptography 代写](https://powcoder.com/category/computer-security/)
26+
- [计算机理论 Computation Theory 代写](https://powcoder.com/category/computation-theory/)
27+
- [计算机视觉(Compute Vision) 代写](https://powcoder.com/category/计算机视觉compute-vision/)
28+

main.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
https://powcoder.com
2+
代写代考加微信 powcoder
3+
Assignment Project Exam Help
4+
Add WeChat powcoder
5+
# You should write your Python program in this file. Currently, it contains
6+
# a skeleton of the methods you will need to write.
7+
8+
import csv
9+
import os
10+
import sqlite3
11+
12+
13+
# in Python, we specify functions using "def" -- this would be equiv to Java
14+
# `public void load_data()`. Note that Python doesn't specify return types.
15+
def load_data():
16+
# This function should:
17+
# 1) create a new database file called "library.db"
18+
# 2) create appropiate tables
19+
# 3) read the data.csv file and insert data into your database
20+
21+
# first, we will check to see if library.db already exists.
22+
# if it does, we will delete it.
23+
if os.path.exists("library.db"):
24+
os.remove("library.db")
25+
26+
# next, we will create a new SQLite database.
27+
28+
# create a database connection.
29+
conn = sqlite3.connect("library.db")
30+
31+
# create a cursor (this is like a single session)
32+
curr = conn.cursor()
33+
34+
# send a pragma command to tell SQLite to check foreign key
35+
# constraints (it does not by default :( )
36+
curr.execute("PRAGMA foreign_keys = ON;")
37+
38+
# here's an example for how to create a table and insert 2 rows into it
39+
# (note the `?` syntax to put values into the query)
40+
curr.execute("CREATE TABLE t ( val1 INTEGER, val2 TEXT )")
41+
curr.execute("INSERT INTO t VALUES(?, ?)",
42+
(8, "this is a test"))
43+
curr.execute("INSERT INTO t VALUES(?, ?)",
44+
(64, "this is another test"))
45+
46+
47+
# commit is like save -- if you don't do it, nothing is written.
48+
conn.commit()
49+
50+
# here's an example of how to read data from the database
51+
curr.execute("SELECT * FROM t")
52+
for row in curr:
53+
# each time through the loop, row[0] will be the first column
54+
# of the result, and row[1] will be the second.
55+
print(row[0], row[1])
56+
57+
conn.close() # close the DB connection when we are done
58+
59+
# here's how to read a CSV file.
60+
with open("data.csv") as f:
61+
reader = csv.reader(f)
62+
next(reader) # throw out the header row
63+
64+
for row in reader:
65+
# row[0] is the first column of the first row
66+
# row[1] is the second column of the first row
67+
print(row)
68+
69+
70+
71+
def overdue_books(date_str):
72+
# This function should take in a string like YYYY-MM-DD and print out
73+
# a report of all books that are overdue as of that date, and the
74+
# patrons who still have them.
75+
76+
pass # delete this when you write your code
77+
78+
def most_popular_books():
79+
# This function should print out a report of which books are the
80+
# most popular (checked out most frequently). The library cares about
81+
# the books themselves, not who published them.
82+
83+
pass # delete this when you write your code
84+
85+
def note_return(patron_card, book_barcode):
86+
# This function should update the database to indicate that the patron
87+
# with the passed card number has returned the book with the given
88+
# barcode. This function should print out an error if that patron didn't
89+
# have the book currently checked out.
90+
91+
pass # delete this when you write your code
92+
93+
def note_checkout(patron_card, book_barcode, checkout_date):
94+
# This function should update the database to indicate that a patron
95+
# has checked out a book on the passed date. The due date of the book
96+
# should be 7 days after the checkout date. This function should print
97+
# out an error if the book is currently checked out.
98+
99+
pass # delete this when you write your code
100+
101+
def replacement_report(book_barcode):
102+
# This function will be used by the library when a book has been lost
103+
# by a patron. It should print out: the publisher and publisher's contact
104+
# information, the patron who had checked out the book, and that patron's
105+
# phone number.
106+
107+
pass # delete this when you write your code
108+
109+
def inventory():
110+
# This function should report the library's inventory, the books currently
111+
# available (not checked out).
112+
113+
pass # delete this when you write your code
114+
115+
# this is the entry point to a Python program, like `public static void main`
116+
# in Java.
117+
if __name__ == "__main__":
118+
while True:
119+
print("Hello! Welcome to the library system. What can I help you with today?")
120+
print("\t1) Load data")
121+
print("\t2) Overdue books")
122+
print("\t3) Popular books")
123+
print("\t4) Book return")
124+
print("\t5) Book checkout")
125+
print("\t6) Book replacement")
126+
print("\t7) Inventory")
127+
print("\t8) Quit")
128+
129+
user_response = int(input("Select an option: "))
130+
131+
if user_response == 1:
132+
load_data()
133+
elif user_response == 2:
134+
date = input("Date (YYYY-MM-DD): ")
135+
overdue_books(date)
136+
elif user_response == 3:
137+
most_popular_books()
138+
elif user_response == 4:
139+
patron = input("Patron card: ")
140+
book = input("Book barcode: ")
141+
note_return(patron, book)
142+
elif user_response == 5:
143+
patron = input("Patron card: ")
144+
book = input("Book barcode: ")
145+
chd = input("Checkout date (YYYY-MM-DD): ")
146+
note_checkout(patron, book, chd)
147+
elif user_response == 6:
148+
book = input("Book barcode: ")
149+
replacement_report(book)
150+
elif user_response == 7:
151+
inventory()
152+
elif user_response == 8:
153+
break
154+
else:
155+
print("Unrecognized option. Please try again.")
156+
157+

pa2.pdf

130 KB
Binary file not shown.

0 commit comments

Comments
 (0)