Quiz 16_3-2: Databases | Python for Everybody 配套练习_解题记录

news2025/1/13 10:03:14

文章目录

  • 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)

  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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)

TrackArtistAlbumGenre
Chase the AceAC/DCWho Made WhoRock
D.T.AC/DCWho Made WhoRock
For Those About To Rock (We Salute You)AC/DCWho Made WhoRock

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/703646.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

数据库管理-第八十七期 19c OCM之路-第一堂(02)(20230630)

第八十六期 19c OCM之路-第一堂(02) 本来计划是昨天写的,但是昨天突发膝盖筋膜炎,去骨科医院做了下治疗,前后两夜几乎无眠。本期内容主要是针对第一堂第四个考点:Manage application containers内容去做的…

Spring Boot中的@MessageMapping注解:原理及使用

Spring Boot中的MessageMapping注解:原理及使用 简介 在Web应用程序中,实现实时的双向通信是一项重要的功能。为了实现这种功能,需要使用WebSocket协议。Spring框架提供了Spring WebSocket模块来实现WebSocket通信。Spring Boot是基于Sprin…

《刷题日记03》链表

题目描述力扣https://leetcode.cn/problems/LGjMqU/ 给定一个单链表 L 的头节点 head ,单链表 L 表示为: L0 → L1 → … → Ln-1 → Ln 请将其重新排列后变为: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → … 不能只是单纯的改变节点内部的值…

实例003 像开始菜单一样漂亮的菜单

实例说明 Windows的开始菜单非常的独特,在菜单的旁边有一条竖着的彩条,彩条中还写着文字。这种独特的菜单能够使程序的界面看起来更加的漂亮。本例中就实现了这种菜单,运行本例弹出“打开菜单”时,就会看到菜单的左边有一个紫色的…

ChatGPT微调系列一:微调 流程

文章目录 前言一、啥叫微调二、为啥要微调三、不是所有模型都可以微调的四、总述微调的基本流程,以及涉及的主要函数,参数1. 安装2. 准备训练数据3. openai.api_key os.getenv() 进行一个说明4. 通过API 调用模型 常用函数5. 微调模型 常用函数6. OpenA…

【论文阅读】Self-supervised Image-specific Prototype Exploration for WSSS

一篇CVPR2022上的论文,用于弱监督分割 论文标题: Self-supervised Image-specific Prototype Exploration for Weakly Supervised Semantic Segmentation 作者信息: 代码地址: https://github.com/chenqi1126/SIPE 论文链接&…

【doxygen】markdown 表格中插入换行与缩进

文章目录 markdown 表格换行markdown 标准换行doxygen 中 markdown 表格换行 markdown 表格缩进 doxygen 中使用 markdown markdown 表格换行 markdown 表格生成 doxygen 时换行与标准的 markdown 语法稍有差异 markdown 标准换行 markdown 中可以使用 html 的换行标签 <…

Python学习之文件操作【基本操作,JSON文件操作】

前言 Python的文件操作是一个非常重要的主题&#xff0c;它可以用来读取&#xff0c;写入和操作各种类型的文件&#xff0c;包括文本文件、图像文件、音频文件等。在这里&#xff0c;我们将讨论一些基本的Python文件操作和JSON文件操作。 Python文件操作 Python提供了多种方…

73、基于51单片机温湿度光照检测控制esp8266无线WiFi app远程监测报警(程序+原理图+PCB源文件+参考论文+开题报告+元器件清单等)

研究目的 现代的生活中&#xff0c;许多情况都对环境的温湿度有比较严格的要求&#xff0c;因此&#xff0c;必须在某些特定环境安装温湿度报警器对环境的温湿度进行监控和调节。为此&#xff0c;本题目选用花卉温室的温湿度调节为背景环境&#xff0c;研究利用集成温湿度传感…

赛效:PDF文件怎么加密

1&#xff1a;在网页上打开并登录91ai工具&#xff0c;在特色功能里点击“PDF加密”。 2&#xff1a;点击上传文件&#xff0c;将本地PDF文件添加上去。 3&#xff1a;文件上传成功后&#xff0c;在文件下方设置密码后点击“开始加密”。 4&#xff1a;加密完成后点击下方下载按…

YOLOv5改进系列(12)——更换Neck之BiFPN

【YOLOv5改进系列】前期回顾: YOLOv5改进系列(0)——重要性能指标与训练结果评价及分析 YOLOv5改进系列(1)——添加SE注意力机制

浅谈安科瑞电力监控系统解决方案 安科瑞 许敏

摘要&#xff1a;随着经济的发展&#xff0c;能源消耗速度正不断加快&#xff0c;因此我国提出了绿色可持续发展战略&#xff0c;要求在发展建设中以节能为主&#xff0c;不断减少资源能耗&#xff0c;而电能便是首要控制内容。如今我国为电能使用&#xff0c;对计量表进行了优…

Web 应用程序综合监控

综合监控是什么意思 模拟用户通过 Web 应用程序的旅程并对其进行监控以检测任何增加延迟的元素的过程被广泛称为综合监控或综合测试。 为什么需要综合监测 为了确保最终用户的无缝体验&#xff0c;综合性能监控势在必行。监视综合事务以帮助您了解用户如何与 Web 应用程序交…

flex布局瀑布流占位两边对齐不对称

.page{display: flex;justify-content: space-between;flex-wrap: wrap; }.page:after {content: ;width: 400px; // 也可以 flex:1}

压缩文件——干货代码分享

1.背景 最近写接口遇到通过FTP服务器发送文件的需求&#xff0c;文件内容需加密并压缩&#xff0c;故记录一下&#xff0c;提供已经测试通过的代码。 2.代码 package com.example.demo.utils;import lombok.extern.slf4j.Slf4j;import java.io.*; import java.util.zip.GZIPOu…

大学智慧课堂系统整理

目录 一、题目类型选择器(非组件库) 1.1、效果展示 1.2、代码展示 二、题目类型选择器(Vant组件库) 2.1、效果展示 2.2、代码展示 一、题目类型选择器(非组件库) 使用vue2&#xff1a;在methods里区分单个点击和多个点击&#xff0c;在view视图区分判断题和选择题。 如下…

正则表达式和BeautifulSoup

文章目录 1、正则表达式介绍2、正则表达式和BeautifulSoup3、获取属性4、Lambda表达式 1、正则表达式介绍 正则表达式是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串。它描述了一种字符串匹配的模式&#xff08;pattern&#xff09;&#xff0c;可以用来…

​Nature |HiFi宏基因组助力挖掘海洋“新”微生物组

近期在《Nature》发表的一篇研究论文中&#xff0c;表述了如何在罕见的微生物类群和环境中研究未知的酶和天然产物&#xff0c;研究突出了微生物组学在深入挖掘天然产物合成与酶学机制中的关键作用&#xff0c;对海洋生态、进化、生物技术与天然产物等领域的研究具有重要意义。…

基于Java+Vue前后端分离乐购游戏商城系统设计实现(源码+lw+部署文档+讲解等)

博主介绍&#xff1a;✌全网粉丝30W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专…

制造企业可以通过数字工厂管理系统降低采购成本吗

制造企业可以通过数字工厂管理系统降低采购成本。制造业数字工厂系统是一种基于数字化技术的管理系统&#xff0c;可以帮助企业实现生产过程的数字化管理&#xff0c;提高生产效率和降低生产成本。下面具体介绍数字工厂管理系统如何降低制造企业的采购成本。 一、优化采购计划 …