文章目录
- Python for Everybody
- 课程简介
- Quiz 16_3-3: Databases
- 单选题(1-10)
- 操作题
- Autograder: Many Students in Many Courses
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-3: 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)
- How do we model a many-to-many relationship between two database tables?
- We use a BLOB column in both tables
- We use the ARRAY column type in both of the tables
- We add 10 foreign keys to each table with names like artict_id_1, artist_id2, etc.
- We add a table with two foreign keys
- In Python, what is a database “cursor” most like?
- A function
- A Python dictionary
- A method within a class
- A file handle
- What method do you call in an SQLIte cursor object in Python to run an SQL command?
- send()
- run()
- execute()
- socket()
- In the following SQL,
cur.execute('SELECT count FROM Counts WHERE org = ? ', (org, ))
what is the purpose of the “?”?
- It is a syntax error
- It is a placeholder for the contents of the “org” variable
- It allows more than one boolean operation in the WHERE clause
- It is a search wildcard
- In the following Python code sequence (assuming cur is a SQLite cursor object),
cur.execute('SELECT count FROM Counts WHERE org = ? ', (org, ))
row = cur.fetchone()
what is the value in row if no rows match the WHERE clause?
- -1
- None
- An empty dictionary
- An empty list
- What does the LIMIT clause in the following SQL accomplish?
SELECT org, count FROM Counts
ORDER BY count DESC LIMIT 10
- It only sorts on the first 10 characters of the column
- It reverses the sort order if there are more than 10 rows
- It only retrieves the first 10 rows from the table
- It avoids reading data from any table other than Counts
- What does the executescript() method in the Python SQLite cursor object do that the normal execute() method does not do?
- It allows multiple SQL statements separated by semicolons
- It allows database tables to be created
- It allows embeded Python to be executed
- It allows embedded JavaScript to be executed
- What is the purpose of “OR IGNORE” in the following SQL:
INSERT OR IGNORE INTO Course (title) VALUES ( ? )
- It ignores errors in the SQL syntax for the statement
- It makes sure that if a particular title is already in the table, there are no duplicate rows inserted
- It ignores any foreign key constraint errors
- It updates the created_at value if the title already exists in the table
- For the following Python code to work, what must be added to the title column in the CREATE TABLE statement for the Course table:
cur.execute('''INSERT OR IGNORE INTO Course (title)
VALUES ( ? )''', ( title, ) )
cur.execute('SELECT id FROM Course WHERE title = ? ',
(title, ))
course_id = cur.fetchone()[0]
- An AUTOINCREMENT indication
- A UNIQUE constraint
- A PRIMARY KEY indication
- A NOT NULL constraint
- What do we generally avoid in a many-to-many junction table?
- Data items specific to the many-to-many relationship
- A logical key
- Two foreign keys
- An AUTOINCREMENT primary key column
操作题
Autograder: Many Students in Many Courses
Instructions
This application will read roster data in JSON format, parse the file, and then produce an SQLite database that contains a User, Course, and Member table and populate the tables from the data file.
You can base your solution on this code: http://www.py4e.com/code3/roster/roster.py - this code is incomplete as you need to modify the program to store the role column in the Member table to complete the assignment.
Each student gets their own file for the assignment. Download this file and save it as roster_data.json
. Move the downloaded file into the same folder as your roster.py
program.
Once you have made the necessary changes to the program and it has been run successfully reading the above JSON data, run the following SQL command:
SELECT User.name,Course.title, Member.role FROM
User JOIN Member JOIN Course
ON User.id = Member.user_id AND Member.course_id = Course.id
ORDER BY User.name DESC, Course.title DESC, Member.role DESC LIMIT 2;
The output should look as follows:
Zuzu|si422|0
Zunairah|si334|0
Once that query gives the correct data, run this query:
SELECT 'XYZZY' || hex(User.name || Course.title || Member.role ) AS X FROM
User JOIN Member JOIN Course
ON User.id = Member.user_id AND Member.course_id = Course.id
ORDER BY X LIMIT 1;
You should get one row with a string that looks like XYZZY53656C696E613333.
(Hint: starts with XYZZY41616
)