Question

Chapter 08 Python Assignment: Question 1-5 Please I need help in my python course. Question 1...

Chapter 08 Python Assignment: Question 1-5

Please I need help in my python course.

Question 1

  1. The finally clause of a try statement

    a.

    can be used to recover from an exception

    b.

    is required

    c.

    can be used to display more information about an exception

    d.

    is executed whether or not an exception has been thrown

10 points

Question 2

  1. Which of the following is the correct way to code a try statement that catches any type of exception that can occur in the try clause?

    a.

    try:
        number = float(input("Enter a number: "))
        print("Your number is: ", number)
    except:

         print("Invalid number.")

    b.

    try:
        number = float(input("Enter a number: "))

        print("Your number is: ", number)

    c.

    try:
        number = float(input("Enter a number: "))
        print("Your number is: ", number)
    except ValueError:

         print("Invalid number.")

    d.

    try:
        number = float(input("Enter a number: "))
        print("Your number is: ", number)
    else:
         print("Invalid number.")

10 points

Question 3

  1. Which of the following is the correct way to code a try statement that displays the type and message of the exception that’s caught?

    a.

    try:
        number = int(input("Enter a number: "))
        print("Your number is: ", number)
    except Exception:
         print(Exception(type), Exception(message))

    b.

    try:
        number = int(input("Enter a number: "))
        print("Your number is: ", number)
    except Exception as e:
        print(type(e), e)

    c.

    try:
        number = int(input("Enter a number: "))
        print("Your number is: ", number)
    except Exception as e:
        print(e(type), e(message))

    d.

    try:
        number = int(input("Enter a number: "))
        print("Your number is: ", number)
    except Exception:
         print(type(Exception), Exception)

10 points

Question 4

  1. It’s a common practice to throw your own exceptions to test error handling routines that

    a.

    handle many varieties of input

    b.

    that handle complexities like lists within lists

    c.

    catch exceptions that are hard to produce otherwise

    d.

    provide for many different types of exceptions

10 points

Question 5

  1. When an exception is thrown, Python creates an exception object that contains all but one of the following items of information. Which one is it?

    a.

    the message for the exception

    b.

    the type of exception

    c.

    the severity of the exception

    d.

    the name of the class for the type of exception

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Question 1:
B. is executed whether or not an exception has been thrown


Question 2:
a.
try:
    number = float(input("Enter a number: "))
    print("Your number is: ", number)
except:
     print("Invalid number.")


Question 3:
b.
try:
    number = int(input("Enter a number: "))
    print("Your number is: ", number)
except Exception as e:
    print(type(e), e)

Question 4:
catch exceptions that are hard to produce otherwise

Question 5:
C. the severity of the exception
Add a comment
Know the answer?
Add Answer to:
Chapter 08 Python Assignment: Question 1-5 Please I need help in my python course. Question 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Which of the following is the correct way to code a try statement that displays the...

    Which of the following is the correct way to code a try statement that displays the type and message of the exception that’s caught? try: number = int(input("Enter a number: ")) print("Your number is: ", number) except Exception as e: print(e(type), e(message)) try: number = int(input("Enter a number: ")) print("Your number is: ", number) except Exception as e: print(type(e), e) try: number = int(input("Enter a number: ")) print("Your number is: ", number) except Exception: print(Exception(type), Exception(message)) try: number = int(input("Enter...

  • use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main...

    use python IDEL Please highlight the answer Problem 1 Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...

  • use python IDEL Please highlight the answer 1 ווCIוסטIT Errors and Exceptions. There are two main...

    use python IDEL Please highlight the answer 1 ווCIוסטIT Errors and Exceptions. There are two main types of errors: syntax errors and runtime errors. Syntax errors are detected by the Python interpreter before the program execution during the parsing stage (parsing is a process, during which the Python interpreter analyzes the grammatical structure of the program). Runtime errors are errors in a program that are not detected by the Python interpreter during its parsing stage. They are further divided into...

  • 12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try...

    12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the...

    Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the following program? public class Quiz2B { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question 1 options: The program displays Welcome to Java two times. The program displays Welcome to...

  • C++ with comments please! // numberverifier.cpp #include <iostream> #include <exception> using std::cout; using std::cin; using std::endl;...

    C++ with comments please! // numberverifier.cpp #include <iostream> #include <exception> using std::cout; using std::cin; using std::endl; #include <cmath> #include <cstring> class nonNumber : public exception { public: /* write definition for the constructor */ -- Message is “An invalid input was entered” }; int castInput( char *s ) { char *temp = s; int result = 0, negative = 1; // check for minus sign if ( temp[ 0 ] == '-' ) negative = -1; for ( int i...

  • import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {              ...

    import java.util.Scanner; import java.io.File; public class Exception2 {        public static void main(String[] args) {               int total = 0;               int num = 0;               File myFile = null;               Scanner inputFile = null;               myFile = new File("inFile.txt");               inputFile = new Scanner(myFile);               while (inputFile.hasNext()) {                      num = inputFile.nextInt();                      total += num;               }               System.out.println("The total value is " + total);        } } /* In the first program, the Scanner may throw an...

  • QUESTION 21 while True: , in Python, can be used to create an infinite loop. True...

    QUESTION 21 while True: , in Python, can be used to create an infinite loop. True False 2 points    QUESTION 22 The Python Framework does inform you where an error occurred True False 2 points    QUESTION 23 ____ is a critical component to being able to store data and information long term. File Access Memory Print function with 2 points    QUESTION 24 Error handling is also known as ___ handling Result Recursion Exception Crash 2 points   ...

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT