Chapter 7 Quiz

10 试题

1.

Given the architecture and terminology we introduced in Chapter 1, where are files stored?

Main Memory

Machine Language

Secondary memory

Motherboard

2.

What is stored in a "file handle" that is returned from a successful open() call?

All the data from the file is read into memory and stored in the handle

The handle has a list of all of the files in a particular folder on the hard drive

The handle contains the first 10 lines of a file

The handle is a connection to the file's data

3.

What do we use the second parameter of the open() call to indicate?

The list of folders to be searched to find the file we want to open

Whether we want to read data from the file or write data to the file

How large we expect the file to be

What disk drive the file is stored on

4.

What Python function would you use if you wanted to prompt the user for a file name to open?

file_input()

cin

read()

raw_input()

5.

What is the purpose of the newline character in text files?

It enables random movement throughout the file

It indicates the end of one line of text and the beginning of another line of text

It adds a new network connection to retrieve files from the network

It allows us to open more than one files and read them in a synchronized manner

6.

If we open a file as follows:

xfile = open('mbox.txt')

What statement would we use to read the file one line at a time?

for line in xfile:

while ((line = xfile.readLine()) != null) {

while (<xfile>) {

while line = xfile.gets

7.

What is the purpose of the following Python code?

fhand = open('mbox.txt')
x = 0
for line in fhand:x = x + 1
print x

Reverse the order of the lines in mbox.txt

Count the lines in the file 'mbox.txt'

Remove the leading and trailing spaces from each line in mbox.txt

Convert the lines in mbox.txt to lower case

8.

If you write a Python program to read a text file and you see extra blank lines in the output that are not present in the file input as shown below, what Python string function will likely solve the problem?

From: stephen.marquard@uct.ac.zaFrom: louis@media.berkeley.eduFrom: zqian@umich.eduFrom: rjlowe@iupui.edu...

strip()

ljust()

find()

startswith()

9.

The following code sequence fails with a traceback when the user enters a file that does not exist. How would you avoid the traceback and make it so you could print out your own error message when a bad file name was entered?

fname = raw_input('Enter the file name: ')
fhand = open(fname)

setjmp / longjmp

try / catch / finally

try / except

signal handlers

10.

What does the following Python code do?

fhand = open('mbox-short.txt')
inp = fhand.read()

Checks to see if the file exists and can be written

Prompts the user for a file name

Reads the entire file into the variable inp as a string

Turns the text in the file into a graphic image like a PNG or JPG

Coursera课程Python for everyone:chapter7相关推荐

  1. Coursera课程Python for everyone:Quiz: Many-to-Many Relationships and Python

    Many-to-Many Relationships and Python 9 试题

  2. Coursera课程Python for everyone:Quiz: Multi-Table Relational SQL

    Multi-Table Relational SQL 10 试题 1. What is the primary added value of relational databases over fla ...

  3. Coursera课程Python for everyone:Quiz: Single-Table SQL

    Single-Table SQL 11 试题 1. Structured Query Language (SQL) is used to (check all that apply) Delete d ...

  4. Coursera课程Python for everyone:Quiz: Object Oriented Programming

    Object Oriented Programming 11 试题 1. Which came first, the instance or the class? instance class fun ...

  5. Coursera课程Python for everyone:Quiz: REST, JSON, and APIs

    REST, JSON, and APIs 10 试题 1. Who is credited with getting the JSON movement started? Pooja Sankar M ...

  6. Coursera课程Python for everyone:Quiz: eXtensible Markup Language

    eXtensible Markup Language 10 试题 1. What is "serialization" when we are talking about web ...

  7. Coursera课程Python for everyone:Quiz: Reading Web Data From Python

    Reading Web Data From Python 8 试题 1. Which of the following Python data structures is most similar t ...

  8. Coursera课程Python for everyone:Quiz: Networks and Sockets

    Networks and Sockets 10 试题 1. What do we call it when a browser uses the HTTP protocol to load a fil ...

  9. Coursera课程Python for everyone:Quiz: Regular Expressions

    Quiz: Regular Expressions 10 试题 1. Which of the following best describes "Regular Expressions&q ...

最新文章

  1. 关于 synchronizeOnSession
  2. 硬解析优化_解析!解析!598元的山灵动圈耳机大杀器,横评对比心慌慌
  3. 切换执行等级的命令init
  4. 编写Linux内核模块——第三部分:按键和发光二极管
  5. openStack 租户控制台修改虚拟机账户密码
  6. NIO入门系列之第3章:从理论到实践:NIO 中的读和写
  7. 一个QQ旋风的BUG
  8. 【BUG记录】记一次游戏越来越卡的BUG
  9. OpenGL油画效果
  10. Oracle监听的静态注册和动态注册
  11. 《Win测试的学习笔记》——Introduction
  12. Qt error: collect2: error: ld returned 1 exit status
  13. 【性能之旅】Andrew 领衔,RWP 团队再临北京
  14. 我为什么选择使用Go语言?
  15. 互联网快讯:极米Z6X Pro、极米H3S获用户青睐;民德电子功率半导体赛道获进展
  16. 【Rust日报】2021-09-05 perseus:完全支持 SSR 和 SSG 的 Rust 高端前端开发框架
  17. 这是请程序员设计的楼梯吧
  18. 教你快速给多段视频添加同一个片尾和转场特效
  19. c++ 鼠标切换形状
  20. java 8——Stream

热门文章

  1. DeepMind哈萨比斯对话哈里王子:2018年AI最大的突破在生物或化学 2017-12-29 新智元 新智元报道 编辑:刘小芹 胡祥杰 【新智元导读】BBC 电台第四台连续第14年在
  2. 再理解RankNet算法
  3. jvm性能调优实战 - 48无限循环调用和没有缓存的动态代理引起的OOM
  4. 谁会C语言,谁会c语言程序设计
  5. python 文件末尾增加内容_java追加内容到文件末尾
  6. ROS知识【12】:用户的功能包覆盖系统功能包
  7. 计算机网络多线程通信,多线程技术的PLC与PC的通讯方式
  8. 链接oracle 无监听程序,连接ORACLE 无监听程序
  9. matlab潮流程序,IEEE33节点matlab潮流程序.doc
  10. linux vi 批量修改某类字符串