文章目录
- Python for Everybody
- 课程简介
- Quiz 16_3-2: Databases
- 单选题(1-10)
- 操作题
- Autograder 1: Counting Email in a Database
- Autograder 2: Multi-Table Database - Tracks
Python for Everybody
课程简介
Python for Everybody 零基础程序设计(Python 入门)
- This course aims to teach everyone the basics of programming computers using Python. 本课程旨在向所有人传授使用 Python 进行计算机编程的基础知识。
- We cover the basics of how one constructs a program from a series of simple instructions in Python. 我们介绍了如何通过 Python 中的一系列简单指令构建程序的基础知识。
- The course has no pre-requisites and avoids all but the simplest mathematics. Anyone with moderate computer experience should be able to master the materials in this course. 该课程没有任何先决条件,除了最简单的数学之外,避免了所有内容。任何具有中等计算机经验的人都应该能够掌握本课程中的材料。
- This course will cover Chapters 1-5 of the textbook “Python for Everybody”. Once a student completes this course, they will be ready to take more advanced programming courses. 本课程将涵盖《Python for Everyday》教科书的第 1-5 章。学生完成本课程后,他们将准备好学习更高级的编程课程。
- This course covers Python 3.
coursera
Python for Everybody 零基础程序设计(Python 入门)
Charles Russell Severance
Clinical Professor
个人主页
Twitter
University of Michigan
课程资源
coursera原版课程视频
coursera原版视频-中英文精校字幕-B站
Dr. Chuck官方翻录版视频-机器翻译字幕-B站
PY4E-课程配套练习
Dr. Chuck Online - 系列课程开源官网
Quiz 16_3-2: Databases
Databases give us very fast random access to large amounts of data. There is a lot of material in this chapter as we learn the Structured Query Language (SQL).
单选题(1-10)
- What is the primary added value of relational databases over flat files?
- Ability to store data in a format that can be sent across a network
- Ability to scan large amounts of data quickly
- Ability to execute JavaScript in the file
- Ability to execute Python code within the file
- Ability to quickly convert data to HTML
- What is the purpose of a primary key?
- To look up a row based on a string that comes from outside the program
- To look up a particular row in a table very quickly
- To track the number of duplicate values in another column
- To point to a particular row in another table
- Which of the following is NOT a good rule to follow when developing a database model?
- Model each “object” in the application as one or more tables
- Use a person’s email address as their primary key
- Never repeat string data in more than one table in a data model
- Use integers as primary keys
- If our user interface (i.e., like iTunes) has repeated strings on one column of the user interface, how should we model this properly in a database?
- Put the string in the first row where it occurs and then put that row number in the column of all of the rest of the rows where the string occurs
- Put the string in the last row where it occurs and put the number of that row in the column of all of the rest of the rows where the string occurs
- Put the string in the first row where it occurs and then put NULL in all of the other rows
- Make a table that maps the strings in the column to numbers and then use those numbers in the column
- Encode the entire row as JSON and store it in a TEXT column in the database
- Which of the following is the label we give a column that the “outside world” uses to look up a particular row?
- Local key
- Logical key
- Primary key
- Remote key
- Foreign key
- What is the label we give to a column that is an integer and used to point to a row in a different table?
- Primary key
- Logical key
- Local key
- Foreign key
- Remote key
- What SQLite keyword is added to primary keys in a CREATE TABLE statement to indicate that the database is to provide a value for the column when records are inserted?
- AUTO_INCREMENT
- AUTOINCREMENT
- INSERT_AUTO_PROVIDE
- ASSERT_UNIQUE
- What is the SQL keyword that reconnects rows that have foreign keys with the corresponding data in the table that the foreign key points to?
- COUNT
- APPEND
- JOIN
- CONNECT
- CONSTRAINT
- What happens when you JOIN two tables together without an ON clause?
- You get no rows at all
- The number of rows you get is the number of rows in the first table times the number of rows in the second table
- Leaving out the ON clause when joining two tables in SQLite is a syntax error
- The rows of the left table are connected to the rows in the right table when their primary key matches
- You get all of the rows of the left table in the JOIN and NULLs in all of the columns of the right table
- When you are doing a SELECT with a JOIN across multiple tables with identical column names, how do you distinguish the column names?
- tablename/columnname
- tablename->columnname
- tablename.columnname
- tablename[‘columnname’]
操作题
Autograder 1: Counting Email in a Database
Counting Organizations
This application will read the mailbox data (mbox.txt) and count the number of email messages per organization (i.e. domain name of the email address) using a database with the following schema to maintain the counts.
CREATE TABLE Counts (org TEXT, count INTEGER)
When you have run the program on mbox.txt upload the resulting database file above for grading.
If you run the program multiple times in testing or with different files, make sure to empty out the data before each run.
You can use this code as a starting point for your application: http://www.py4e.com/code3/emaildb.py.
The data file for this application is the same as in previous assignments: http://www.py4e.com/code3/mbox.txt.
Because the sample code is using an UPDATE statement and committing the results to the database as each record is read in the loop, it might take as long as a few minutes to process all the data. The commit insists on completely writing all the data to disk every time it is called.
The program can be speeded up greatly by moving the commit operation outside of the loop. In any database program, there is a balance between the number of operations you execute between commits and the importance of not losing the results of operations that have not yet been committed.
Autograder 2: Multi-Table Database - Tracks
Musical Track Database
This application will read an iTunes export file in XML and produce a properly normalized database with this structure:
CREATE TABLE Artist (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT UNIQUE
);
CREATE TABLE Genre (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name TEXT UNIQUE
);
CREATE TABLE Album (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
artist_id INTEGER,
title TEXT UNIQUE
);
CREATE TABLE Track (
id INTEGER NOT NULL PRIMARY KEY
AUTOINCREMENT UNIQUE,
title TEXT UNIQUE,
album_id INTEGER,
genre_id INTEGER,
len INTEGER, rating INTEGER, count INTEGER
);
If you run the program multiple times in testing or with different files, make sure to empty out the data before each run.
You can use this code as a starting point for your application: http://www.py4e.com/code3/tracks.zip. The ZIP file contains the Library.xml file to be used for this assignment. You can export your own tracks from iTunes and create a database, but for the database that you turn in for this assignment, only use the Library.xml data that is provided.
To grade this assignment, the program will run a query like this on your uploaded database and look for the data it expects to see:
SELECT Track.title, Artist.name, Album.title, Genre.name
FROM Track JOIN Genre JOIN Album JOIN Artist
ON Track.genre_id = Genre.ID and Track.album_id = Album.id
AND Album.artist_id = Artist.id
ORDER BY Artist.name LIMIT 3
The expected result of the modified query on your database is: (shown here as a simple HTML table with titles)
Track | Artist | Album | Genre |
---|---|---|---|
Chase the Ace | AC/DC | Who Made Who | Rock |
D.T. | AC/DC | Who Made Who | Rock |
For Those About To Rock (We Salute You) | AC/DC | Who Made Who | Rock |