Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 06 – An Introduction to Programming using Python Schneider


 

Download  file with the answers

If you are not a member register here to download this file 


 

Chapter 6

1. What do you call runtime errors that usually occur due to circumstances beyond the programmer’s control?
a. exceptions 
b. syntax errors
c. user errors
d. random

2. Which of the following is an example of a runtime error?
a. invalid input data
b. file cannot be accessed
c. both a & b 
d. none of the above

3. _________ is a mechanism in Python that allows the programmer to recover from errors that occur while a program is still running.
a. exception handling 
b. error reporting
c. error catching
d. dynamic programming

4. Which exception flags an error from unavailable functionality that is requested for an object?
a. AttributeError 
b. IndexError
c. FunctionalityError
d. ValueError

5. Which exception flags an error when the value of a variable cannot be found.
a. NameError 
b. ValueError
c. VariableError
d. AttributeError

6. Which exception flags an error when the function or operator receives the wrong type of argument?
a. TypeError 
b. ValueError
c. ArgumentError
d. AttributeError

7. What happens when a runtime error occurs that the programmer has not explicitly addressed with exception handling code?
a. The program terminates.
b. A Traceback error message is displayed.
c. Both a & b. 
d. None of the above.

8. A robust way to explicitly handle exceptions is to protect code with a(n) __________ statement.
a. try 
b. exception
c. handler
d. protection

9. Which one of the following is a reserved word?
a. try
b. except
c. finally
d. all of the above 

10. A program is said to be __________ if it performs well under atypical situations.
a. robust 
b. correct
c. high-performance
d. well-behaved

11. In Python, the numbers generated by the random module are said to be __________.
a. pseudorandom 
b. truly random
c. partially random
d. artificially random

12. Which standard library module are turtle graphics object and methods imported from?
a. turtle 
b. graphics
c. pickle
d. random

13. In Turtle graphics, the white region inside the Window is called the __________.
a. canvas 
b. turtle board
c. turtle
d. chevron

14. In Turtle graphics, points on a canvas are called __________.
a. pixels 
b. dots
c. chevrons
d. turtles

15. In Turtle graphics, the turtles tail is initially located __________.
a. at the origin of the coordinate system 
b. at a random location on the canvas
c. at the bottom middle of the canvas
d. at the top left corner of the canvas

16. In Turtle graphics, the turtle is initially facing __________.
a. east 
b. west
c. north
d. south

17. In Turtle graphics, the tail of the turtle is initially __________.
a. down 
b. up
c. non-existent
d. neither up or down

18. In Turtle graphics, what does the statement t.hideturtle() do?
a. makes the chevron invisible 
b. makes all of the pixels on the canvas invisible
c. resets the standard colors for the canvas
d. resets the original position and orientation of the turtle

19. In Turtle graphics, the write method displays a string with the __________ corner of the string approximately at the current position of the pen.
a. bottom-left 
b. top-left
c. bottom-center
d. top-center

20. A function that calls itself is called __________.
a. recursive 
b. inclusive
c. repetitive
d. a palindrome

21. When does recursion end?
a. When a base case is reached. 
b. When computation becomes too complex to handle.
c. When the looping mechanism completes.
d. When another recursive call is made.

22. Why would you write a recursive solution to a problem?
a. They often generate less code.
b. They are more elegant.
c. They are easier to read.
d. All of the above. 

23. __________ recursion results when two procedures call each other.
a. indirect 
b. infinite
c. inconclusive
d. illegal

True/False (11)
1. When a runtime error occurs, it is the responsibility of the user to correct it.
Answer: false
2. Bad user input can cause runtime errors.
Answer: true
3. A try statement can control more than one except clause.
Answer: true
4. A try statement can include more than one else clause that follows the except clauses.
Answer: false
5. A try statement cannot end with a finally clause.
Answer: false
6. A try statement must contain either an except clause or a finally clause.
Answer: true
7. A single except clause may not refer to more than one type of error.
Answer: false
8. Any problem that can be solved with recursion can be solved with iteration.
Answer: true
9. Iterative solutions usually execute slower than recursive solutions.
Answer: false
10. Recursive solutions often require less code than iterative solutions.
Answer: true

Short Answer (9)
1. What are blocks in finally clauses used for?
Answer: They are typically used for cleaning up resources such as files that are left open.
2. Write a line of Python code to randomly select an item from the list menuitems and assign it to the variable pick.
Answer: pick = random.choice(menuitems)
3. Write a line of Python code to randomly select 4 items from the list menuitems and assign it to the list orders.
Answer: orders = random.sample(menuitems, 4)
4. Write a line of Python code to randomly reorder the list called cards.
Answer: random.shuffle(cards)
5. Write a line of Python code to randomly select a number between 1 and 100, inclusive, and assign it to a variable called guess.
Answer: guess = random.randint(1, 100)
6. What device is used by the algorithm that generates pseudorandom numbers in Python?
Answer: The time on the system clock is used.
7. Given a turtle object called t, write a line of Python Turtle graphics code that moves the turtle to pixel location 100, -150.
Answer: t.goto(100, -150)
8. Given a turtle object called t, write a line of Python Turtle graphics code to display the string “Let’s get moving!” at the current position of the pen.
Answer: t.write(“Let’s get moving!”)
9. Combine the following two Python statements into one Python statement.
t.pencolor(“black”)
t.fillcolor(“red”)
Answer: t.color(“black”, “red”)

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!