Issuu on Google+

Full file at http://testbank360.eu/test-bank-guide-to-programming-with-python-1st-edition-michael-dawson

Chapter 2: Types, Variables, and Simple I/O: The Useless Trivia Program TRUE/FALSE 1. ' "Is this a valid string?", he asked.' is a valid string. ANS: T

PTS: 1

REF: 20

2. A triple-quoted string can be up to three lines long. ANS: F

PTS: 1

REF: 21

3. When two strings are concatenated, Python automatically inserts a space between them. ANS: F

PTS: 1

REF: 26

4. The code "hi" * 3 is not a valid expression in Python. ANS: F

PTS: 1

REF: 27

5. In Python, the result of dividing two integers can sometimes be a float. ANS: F

PTS: 1

REF: 31

6. An assignment statement can create a new variable. ANS: T

PTS: 1

REF: 33

7. _x is a legal variable name in Python. ANS: T

PTS: 1

REF: 34

8. Python variable names can be at most 15 characters long. ANS: F

PTS: 1

REF: 35

9. The raw_input() function always returns a string. ANS: T

PTS: 1

REF: 36

10. The code pront "Hi" produces a logical error when executed. ANS: F

PTS: 1

REF: 41

MULTIPLE CHOICE 1. The escape sequence \n is represented as a(n) what when printed? a. tab c. newline b. system bell d. backslash ANS: C

PTS: 1

REF: 24


Full file at http://testbank360.eu/test-bank-guide-to-programming-with-python-1st-edition-michael-dawson

2. What does the following code display? print "first" + "second" a. first second b. second first ANS: C

c. firstsecond d. secondfirst PTS: 1

REF: 26

3. What does the following code display? print "hi" * 1 a. hi b. hihi ANS: A

c. hi hi d. None of these PTS: 1

REF: 27

4. What is the type of the value 100.0? a. integer b. float ANS: B

c. Boolean d. string PTS: 1

REF: 30

5. What does the expression 21 / 3.0 evaluate to? a. 7 b. 7.0

c. 7.3333333335 d. 3.7777777775

ANS: B

PTS: 1

REF: 31

6. What does the expression 9 / 10 evaluate to? a. 0 b. 0.0

c. 0.9 d. 1

ANS: A

PTS: 1

REF: 31

7. What does the expression 9 % 10 evaluate to? a. -1 b. 1 ANS: C

c. 9 d. 10 PTS: 1

REF: 31

8. What does the following code display? score bonus score print a. 100

= 150 = 50 = score + score score c. 200


Full file at http://testbank360.eu/test-bank-guide-to-programming-with-python-1st-edition-michael-dawson

b. 150 ANS: D

d. 300 PTS: 1

REF: 34

9. raw_input() is an example of a(n) what? a. argument b. float ANS: D

PTS: 1

c. return value d. function

REF: 36

10. In the following code, "Name:" is a(n) what? name = raw_input("Name: ") a. function b. argument ANS: B

c. return value d. parameter PTS: 1

REF: 36

11. In the following code, name is assigned a(n) what? name = raw_input("Name: ") a. function b. argument ANS: C

c. return value d. parameter PTS: 1

REF: 36-37

12. In the following code, upper() is a(n) what? name = "rupert" print name.upper() a. variable b. method ANS: B

c. return value d. argument PTS: 1

REF: 39

13. What does the following code display? name = "HaRoLd" name = name.upper() name = name.swapcase() print name a. HaRoLd b. hArOlD ANS: C

c. harold d. HAROLD PTS: 1

14. What does the following code display? score = "100" bonus = "50" score = int(score + bonus)

REF: 40


Full file at http://testbank360.eu/test-bank-guide-to-programming-with-python-1st-edition-michael-dawson

print score a. 50 b. 150

c. 50100 d. 10050

ANS: D

PTS: 1

REF: 45

15. What does the following code display? score bonus score print

= "100" = "50" = int(score) + int(bonus) score

a. 50 b. 150

c. 50100 d. 10050

ANS: B

PTS: 1

REF: 45

16. int(raw_input("How old are you? ")) is an example of what? a. nesting c. repetition b. looping d. recursion ANS: A

PTS: 1

17. += is an example of a(n) what? a. escape sequence b. augmented assignment operator ANS: B

PTS: 1

REF: 45 c. variable d. argument REF: 45-46

18. What does the following code display? score bonus bonus print

= 150 = 50 += score score

a. 50 b. 100

c. 150 d. 200

ANS: C

PTS: 1

REF: 45-46

19. What does the following code display? score bonus bonus print

= 150 = 50 += score bonus

a. 50 b. 100 ANS: D

c. 150 d. 200 PTS: 1

REF: 45-46


Full file at http://testbank360.eu/test-bank-guide-to-programming-with-python-1st-edition-michael-dawson

20. What does the following code display? score bonus score print

= 150 = 50 += bonus score

a. 50 b. 100 ANS: D

c. 150 d. 200 PTS: 1

REF: 45-46

COMPLETION 1. " is a(n) ____________________ quote. ANS: double PTS: 1

REF: 20

2. ' is a(n) ____________________ quote. ANS: single PTS: 1

REF: 20

3. A(n) ____________________ statement assigns a value to a variable and creates the variable, if necessary. ANS: assignment PTS: 1

REF: 33

4. ____________________ code is written so that it’s easy to understand, independent of any comments. ANS: Self-documenting PTS: 1

REF: 35

5. A(n) ____________________ error doesn’t cause a program to crash, but instead produces unintended results. ANS: logical PTS: 1

REF: 41

MATCHING Match each item with a statement below a. Escape sequence b. Argument

f. Variable g. Return value


Full file at http://testbank360.eu/test-bank-guide-to-programming-with-python-1st-edition-michael-dawson

c. Float d. Integer e. Call

h. Type i. Augmented assignment operator j. Function

1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

To run or execute. Often used to describe executing a function or method. A set of characters that allow you to insert special characters into a string. A numeric type for numbers that have no fractional part. Represents the kind of value something is and determines how the value can be used. A numeric type for numbers that have a fractional part. An operator that assigns a value to a variable based on its current value. A value returned from a function upon completion. A value passed to a function. Represents a value and provides a way to access computer memory. Code that goes off and does some specific task.

1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS:

E A D H C I G B F J

PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS:

1 1 1 1 1 1 1 1 1 1

REF: REF: REF: REF: REF: REF: REF: REF: REF: REF:

36 22 30 30 30 45-46 37 36 | 50 33 36

SHORT ANSWER 1. How can the line continuation character make programs clearer? ANS: The computer doesn’t care how long a programming line is, but people do. If a line of your code feels too long or would be more clear as several lines, use the line-continuation character to split it up. PTS: 1

REF: 20

2. What's the difference between integer division and true division? ANS: When Python performs integer division (where all the numbers involved are integers), the result is always an integer. So, any fractional part is ignored. If you want floating-point division, or what some people call true division, then at least one of your numbers must be a floating-point number. PTS: 1

REF: 31

3. Does Python evaluate the expression 7.0 / 3.0 accurately? ANS:


Full file at http://testbank360.eu/test-bank-guide-to-programming-with-python-1st-edition-michael-dawson

Python says that 7.0 divided by 3.0 evaluates to 2.3333333333333335. While this is pretty accurate, it’s not exact. Computers tend to round floating-point numbers. The results are fine for most purposes. But you should be aware of this when using floats. PTS: 1

REF: 32

4. What four guidelines should you follow to create good variable names? ANS: Choose descriptive names, be consistent, follow the traditions of the language, and keep the length in check. PTS: 1

REF: 34-35

5. Why can logical errors be so difficult to track down? ANS: Logical errors can be the toughest bugs to fix. Because the program doesn’t crash, you don’t get the benefit of an error message to offer a clue. You have to observe the behavior of the program and investigate the code. PTS: 1

REF: 42


Test bank guide to programming with python 1st edition michael dawson