You can connect to Gradescope to take weekly graded quiz today during the last 15 minutes of the class.
Once you start the quiz you have 15 minutes to finish it.
You can only take this quiz today.
There is not makeup for the weekly quiz because Gradescope does not permit it.
If you have the textbook read Chapter 10, Classes and Object-Oriented Programming, sections 10.1 and 10.2, Classes and Object-Oriented Programming and Procedural and Object-Oriented Programming.
I have posted a solution to homework 6 here.
Let's take a look.
I have posted homework 8 here.
It is due this coming Sunday at 11:59 PM.
I have posted the answers to the odd questions here and the answers to the even questions here.
You will find links to them on the class web page.
If you believe I have scored one of your Midterm answers incorrectly you can request a rescore for that question on Gradescope.
If your score on the Final is significantly better than your score on the Midterm, I will replace your Midterm grade with that of the Final when calculating your grade for the course.
If you want to discuss how you can improve your grade in this course, come see me during Office Hours.
You do not have to make an appointment to see me during Office Hours, but you may have to wait your turn if I am helping another student.
I want students to pass this course, and will do what I reasonably can to make that happen.
If you want to know your grade as of this moment, send me an email.
In performing this calculation, I will assume that your score on the final exam will be the same as that of you Midterm score.
I can do this only for your grade as of the Midterm.
I can't do this for your grade later in the semester.
The final for this course will take place in this room on Thursday, December 22th, from 3:00PM - 6:00PM.
You will also find this information at the top of the class web page.
$ sqlite3 SQLite version 3.16.0 2016-11-04 19:09:39 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite>
sqlite> select * from students; student_id first_name last_name umb_email user_name college ---------- ---------- ---------- --------------------- ---------- ---------- 09329034 Jane Adams Jane.Adams001@umb.edu jadams CSM 03687480 Alexander Smith Alexander.Smith001@um bigboy CM 05431692 Christophe Cannon Christopher.Cannon001 ccannon CSM 07511379 Joseph Malloney Joseph.Malloney001@um jmal CSM 07518979 Fatih Jones Fatih.Jones001@umb.ed fjones CM 04175276 James Reynolds James.Reynolds001@umb jr CSM
create table students ( student_id text primary key unique, first_name text not null, last_name text not null, umb_email text not null unique, email text unique, user_name text unique, college text );
select COLUMN_LIST from TABLE_NAME where RESTRICTIONS;
sqlite> select student_id, first_name, last_name from students where college = "CM";
student_id first_name last_name
---------- ---------- ----------
03687480 Alexander Smith
07518979 Fatih Jones
insert
command
which has the following syntax
insert into TABLE_NAME (COLUMN_LIST) values (VALUE_LIST);
update TABLE_NAME set(COLUMN_VALUE_PAIRS) where (CONDITION)
delete
command is used to remove a record from a table
delete from TABLE_NAME where CONDITION
sqlite> delete from enrollments where course_id = "it244" and semester_id = "f18";
>>> import sqlite3 >>> sqlite3 <module 'sqlite3' from '/usr/lib/python3.5/sqlite3/__init__.py'>
CONNECTION_OBJECT_VARIABLE = sqlite3.connect(DATABASE_FILENAME)
>>> import sqlite3 >>> con = sqlite3.connect("umb.db")
CURSOR_OBJECT_VARIABLE = CONNECTION_OBJECT_VARIALE.cursor()
>>> cur = con.cursor()
>>> import sqlite3 >>> con = sqlite3.connect("umb.db") >>> cur = con.cursor() >>> cur.execute("select * from students")
for
loop
>>> for row in cur: ... print(row) ... ('09329034', 'Jane', 'Adams', 'Jane.Adams001@umb.edu', 'jadams', 'CSM') ('03687480', 'Alexander', 'Smith', 'Alexander.Smith001@umb.edu', 'bigboy', 'CM') ('05431692', 'Christopher', 'Cannon', 'Christopher.Cannon001@umb.edu', 'ccannon', 'CSM') ('07511379', 'Joseph', 'Malloney', 'Joseph.Malloney001@umb.edu', 'jmal', 'CSM') ('07518979', 'Fatih', 'Jones', 'Fatih.Jones001@umb.edu', 'fjones', 'CM') ('04175276', 'James', 'Reynolds', 'James.Reynolds001@umb.edu', 'jr', 'CSM')
insert
command
>>> cur.execute("insert into enrollments values(null, "it244", 1, "f18", "05431692")")
<sqlite3.Cursor object at 0x7febd141aab0>
insert
commandcon.commit()
update
command to
execute
>>> cur.execute("update students set user_name = "alex" where student_id = "03687480")
<sqlite3.Cursor object at 0x7f15373ffb20>
cur.execute("delete from enrollments where course_id = "it244", section_no = 1, semester = "f18", student_id = "05431692")
<sqlite3.Cursor object at 0x7f15373ffb20>>
insert into enrollments values (null, COURSE_ID, SECTION_NO, SEMESTER_ID, STUDENT_ID)
insert
statement
def enrollment_add(con, course_id, section_no, semester_id, student_id): stmnt = "insert into enrollments values(null, " + course_id + ", " + str(section_no) +\ ", " + semester_id + ", " + student_id + ")" cur = con.cursor() cur.execute(stmnt) cur.close()
YYYY-MM-DD
1970-01-01
MONTH_NAME DAY_OF_MONTH, YEAR
data_file = open(DATA_FILENAME, "r") date_string = data_file.readline()
>>> test_string = "foo bar bletch"
>>> test_string.split() ['foo', 'bar', 'bletch']
>>> date_string.split("-")
['2016', '09', '06\n']
date_string = date_string.strip()
>>> date_string.split("-") ['2016', '09', '06']
>>> year, month, day = date_string.split("-")
>>> year = int(year) >>> month = int(month) >>> day = int(day) >>> year 2016 >>> month 9 >>> day 6
>>> year, month, day = int(year), int(month), int(day) >>> year 2016 >>> month 9 >>> day 6
>>> month_names = {1:"January", 2:"February", 3:"March", 4:"April", ... 5:"May", 6:"June", 7:"July", 8:"August", ... 9:"September", 10:"October", 11:"November", 12:"December"}
>>> month_names[month] 'September'
>>> new_date_string = month_names[month] + " " + str(day) + ", " + str(year) >>> new_date_string 'September 6, 2016'
#! /usr/bin/python3 # code to convert a date in the format # YYYY_MM_DD # stored as the first line in a file whose name # is stored in the variable DATA_FILENAME # into a string in the format # MONTH_NAME DAY_OF_MONTH, YEAR DATA_FILENAME = "data.txt" data_file = open(DATA_FILENAME, "r") # open the file for reading date_string = data_file.readline() date_string = date_string.strip() year, month, day = date_string.split("-") year, month, day = int(year), int(month), int(day) month_names = {1:"January", 2:"February", 3:"March", 4:"April", 5:"May", 6:"June", 7:"July", 8:"August", 9:"September", 10:"October", 11:"November", 12:"December"} new_date_string = month_names[month] + " " + str(day) + ", " + str(year) print(new_date_string)
# opens a file and returns the first line in # that file without the newline def get_first_line(filename): data_file = open(filename, "r") date_string = data_file.readline() data_file.close() return date_string.strip()
# turns a string with a date in the format # YYYY-MM-DD # into integer values for year, month and date def get_date(date_string): year, month, day = date_string.split("-") return int(year), int(month), int(day)
# converts a month number into a month name def get_month_name(month_number): month_names = {1:"January", 2:"February", 3:"March", 4:"April", 5:"May", 6:"June", 7:"July", 8:"August", 9:"September", 10:"October", 11:"November", 12:"December"} return month_names[month_number]
# returns a date in standard format def format_date(year, month, day): return get_month_name(month) + " " + str(day) + ", " + str(year)
#! /usr/bin/python3
# code to convert a date in the format
# YYYY_MM_DD
# stored as the first line in a file whose name
# is stored in the variable DATA_FILENAME
# into a string in the format
# MONTH_NAME DAY_OF_MONTH, YEAR
import date_functions
# opens a file and returns the first line in
# that file without the newline
def get_first_line(filename):
data_file = open(filename, "r")
date_string = data_file.readline()
data_file.close()
return date_string.strip()
DATA_FILENAME = "data.txt"
date_string = get_first_line(DATA_FILENAME)
year, month, day = date_functions.get_date(date_string)
print(date_functions.format_date(year, month, day))
def __init__(self, date_string): self.year, self.month, self.day = date_string.split("-") self.year = int(self.year) self.month = int(self.month) self.day = int(self.day)
return
statementreturn
statement to do this# converts a month number into a month name def get_month_name(self): month_names = {1:"January", 2:"February", 3:"March", 4:"April", 5:"May", 6:"June", 7:"July", 8:"August", 9:"September", 10:"October", 11:"November", 12:"December"} return month_names[self.month]
self.month
# returns a date in standard format def format_date(self): return self.get_month_name() + " " + str(self.day) + ", " + str(self.year)
date_object = Date(date_string)
#! /usr/bin/python3 # code to convert a date in the format # YYYY_MM_DD # stored as the first line in a file whose name # is stored in the variable DATA_FILENAME # into a string in the format # MONTH_NAME DAY_OF_MONTH, YEAR # Uses the Date class from date import Date # opens a file and returns the first line in # that file without the newline def get_first_line(filename): data_file = open(filename, "r") date_string = data_file.readline() data_file.close() return date_string.strip() DATA_FILENAME = "data.txt" date_string = get_first_line(DATA_FILENAME) date_object = Date(date_string) print(date_object.format_date())