Sunteți pe pagina 1din 6

Exercises 1

True/False
1. Computer science is the study of computers.
False. The fundamental question of computer science is 'what can be computed?' To
answer this question, we use design, analysis, and experimentation. (p.4)
2. The CPU is the "brain" of the computer.
True.
3. Secondary memory is also called RAM.
False. The main memory is called RAM. Secondary memory includes hard disks, solid-
state disks (SSD flash memory), USB thumb drives, and optical disks like CDs and DVDs.
(p.6)
4. All information that a computer is currently working on is stored in main memory.
True.
5. The syntax of a language is its meaning, and semantics is its form.
False. The syntax of a language is its form, and the semantics is its meaning. (p.7)
6. A function definition is a sequence of statements that defines a new command.
True.
7. A programming environment refers to a place where programmers work.
False. A programming environment is a program designed to help programmers write
programs. It usually includes auto-indenting, auto-completion, color syntax highlighting,
and interactive development features. (p.12)
8. A variable is used to give a name to a value to it can be referred to in other places.
True.
9. A loop is used to skip over a section of a program.
False. A loop is used to repeat a section of a program. (p.16)
10. A chaotic function can't be computed by a computer.
False. Pages 18-19 demonstrate a chaotic function that is computed by a computer!
Multiple Choice
1. What is the fundamental question of computer science?
(b) What can be computed
2. An algorithm is like a
(d) recipe
3. A problem is intractable when
(d) it is not practical to solve
4. Which of the following is not an example of secondary memory?
(a) RAM
5. Computer languages designed to be used and understood by humans are
(a) high-level languages
6. A statement is
(b) a complete computer command
7. One difference between a compiler and an interpreter is
(c) a compiler is no longer needed after a program is translated
8. By convention, the statements of a program are often placed in a function called
(b) main
9. Which of the following is not true of comments?
(a) They make a program more efficient
10. The items listed in the parentheses of a function definition are called
(d) parameters
Exercises 2
True/False
1. The best way to write a program is to immediately type in some code and then debug it
until it works.
False. There are many steps to writing a program, including first Analyzing the Problem,
Determining Specifications, and Creating a Design. (p.27-28)
2. An algorithm can be written without using a programming language.
True.
3. Programs no longer require modification after they are written and debugged.
False. Programs typically need to be maintained--rewritten and updated--over years of
use. (p.28)
4. Python identifiers must start with a letter or underscore.
True.
5. Keywords make good variable names.
False. Keywords, or reserved words," cannot be used as identifiers. (p.31-32)
6. Expressions are built from literals, variables, and operators.
True.
7. In Python, x = x + 1 is a legal statement.
True.
8. Python does not allow the input of multiple variable with a single statement.
False. The program on page 42 provides an example of multiple variable input.
9. A counted loop is designed to iterate a specific number of times.
True.
10. In a flowchart, diamonds are used to show statements, and rectangles are used for
decision points.
False. Diamonds are used for decisions, and rectangles for statements. (p. 45). Note that
flowcharts aren't typically used in developing programs anymore. They have been
replaced by pseudocode.
Multiple Choice
1. What of the following is not a step in the software development process?
(c) Fee setting
2. What is the correct forumla for converting Celsius to Fahrenheit?
(a) F = 9/5(C) + 32
3. The process of describing exactly what a computer program will do to solve a problem is
called
(d) specification
4. Which of the following is not a legal identifier?
(a) 2spam
5. Which of the following are not used in expressions?
(b) statements
6. Fragments of code that produce or calculate new data values are called
(d) assignment statements
7. Which of the following is not part of the IPO pattern?
(b) Program
8. The template for <variable> in range(<expr>) describes
(a) a general for loop
or
(d) a counted loop
9. Which of the following is the most accurate model of assignment in Python?
(a) sticky note (although you'll often see analysis of programs using the variable-as-
box diagram)
10. In Python getting user input is done with a special expression called
(d) input
Exercise 3
True/False
1. Information that is stored and manipulated by computers is called data.
True.
2. Since floating point numbers are extremely accurate, they should generally be used
instead of ints.
False. There are advantage to using floats--they can represent fraction or decimal
values--but they have the disadvantage of being slower to calculate with, and
unnecessary for some types of calculations. (p.57)
3. Operations like addition and subtraction are defined in the math library.
False. Addition and subtraction are built in to Python, while the math library defines
additional math functions such as pi, sqrt(x), log(x), etc. (p.60-63) If you want to use
the math library, be sure to import it with an import math statement at the beginning of
the program.
4. The number of possible rearrangements of n items is equal to n!.
True.
5. The sqrt function computes the squirt of a number.
False. sqrt(x) returns the square root of x. (p.63)
6. The int data type is identical to the mathematical concept of integer.
True.
7. Computers represent numbers using base 2 representations.
True.
8. A hardware float can represent a larger range of values than a hardware int.
True.
9. A Python int can represent indefinitely large numbers.
False. Python is flexible in handling large int values, but it is ultimately limited by the
amount of computer memory available. (p. 68-69)
10. In Python, 4+5 produces the same result type as 4.0+5.0.
False. 4+5 produces in integer result, while 4.0+5.0 produces a floating point result.
(p.58 has examples)
Multiple Choice
1. What of the following is not a Python data type?
(c) rational
2. Which of the following is not a built-in operation?
(d) sqrt()
3. In order to use functions in the math library, a program must include
(d) an import statement
4. The value of 4! is
(b) 24
5. The most appropriate data type for storing the value of pi is
(b) float
6. The number of distinct values that can be represented using 5 bits is
(c) 32
7. In a mixed-type expression involving ints and floats, Python will convert
(d) ints to floats
8. Which of the following is not a Python type-conversion function?
(d) abs

9. The pattern used to computer factorial is


(a) accumulator
10. In modern Python, an int value that grows larger than the underlying hardware int
(d) uses more memory
Exercises 4
True/False
1. Using graphics.py allows graphcs to be drawn into a Python shell window.
False. The Python shell window does not have the ability to draw graphics. A graphical
window must be opened so that graphics can be drawn in it. (p.82-83)
2. Traditionally, the upper-left corner of a graphics window has coordinates (0,0).
True.
3. A single point on a graphics screen is called a pixel.
True. ("Pixel" = "picture element")
4. A function that creates a new instance of a class is called an accessor.
False. The function that creates a new instance is called a *constructor. (p. 87)*
5. Instance variables are used to store data inside an object.
True.
6. The statement myShape.move(10,20) moves myShape to the point (10,20).
False. The move(10,20) method call moves the object 10 pixels to the right from where
it's currently located, and 20 pixels down from that location (p. 88)
7. Aliasing occurs when two variables refer to the same object.
True, although this term in a graphics context can also refer to the blur that can occur at
low resolutions (a signal processing problem).
8. The copy method is provided to make a copy of a graphics object.
False. The clone method is used. (p. 91)
9. A graphics window always has the title "Graphics Window."
False. That's the default title, but it's possible to create a different title for the window. (p.
94)
10. The method in the graphics library used to get a mouse click is readMouse.
False. The method for this is the getMouse method. (p. 108)

Multiple Choice
1. A method that returns the value of an object's instance variable is called a(n)
(d) accessor
2. A method that changes the state of an object is called a(n)
(b) mutator
3. What graphics class would be best for drawing a square?
(d) Rectangle
4. What command would set the coordinates of win to go from (0,0) in the lower-left corner
to (10,10) in the upper-right?
(c) win.setcoords(0, 0, 10, 10)
5. What expression would create a line from (2,3) to (4,5)?
(d) Line(Point(2,3), Point(4,5))
6. What comand would be used to draw the graphics object shape into the graphics
window win?
(d) shape.draw(win)
7. Which of the following computes the horizontal distance between points p1 and p2?
(d) abs(p1.getX() - p2.getX())
8. What kind of object can be used to get text input in a graphics window?
(b) Entry
9. A user interface organized around visual elements and user actions is called a(n)
(a) GUI
10. What color is `color_rgb(0,255,255)?
(b) cyan

Exercises 5
True/False
1. A Python string literal is ealways enclosed in double quotes.
False. A Python string may be enclosed in single quotes. (p. 122)
2. The last character of a string s is at position len(s) - 1.
True. And you can access that character as s[len(s) - 1], but a better way would be to
say s[-1].
3. A string always contains a single line of text.
False. A string may contain no lines of text, or multiple lines of text. (p. 152)
4. In Python "4" + "5" is "45".
True.
5. Python lists are mutable, but strings are not.
True.
6. ASCII is a standard for representing characters using numeric codes.
True.
7. The split method breaks a string into a list of stubstrings, and join does the opposite.
True.
8. A substitution cipher is a good way to keep sensitive information secure.
False. Substitution ciphers are easily broken by a number of methods, including brute-
force and frequency analysis. (p. 142)
9. The add method can be used to add an item to the end of a list.
False. The append method is used to add an item to the end of a list in Python. (p. 139)
10. The process of associating a file with an object in a program is called "reading" the file.
False. This process is called "opening" the file. Once the file is opened, then it can be
read into a program. (p. 153)
Multiple Choice
1. Accessing a single character out of a string is called:
(d) indexing (although slicing is often used as well)
2. Which of the following is the same as s[0:-1]?
(c) s[:len(s)-1]
3. What function gives the Unicode value of a character?
(a) ord
4. Which of the following can not be used to convert a string of digits into a number?
(c) str
5. A successor to ASCII that includes characters from (nearly) all written languages is
(c) Unicode
6. Which string method converts all the characters of a string to upper case?
(d) upper
7. The string "slots that are filled in by the format method are marked by:
(d) {}
8. Which of the following is not a file-reading method in Python?
(c) readall
9. The term for a program that does its I/O with files is
(c) batch
10. Before reading or writing to a file, a file object must be created via
(a) open

S-ar putea să vă placă și