Chapter 08 Python Assignment: Question 1-5
Please I need help in my python course.
Question 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
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: |
|
| b. |
try: |
|
| c. |
try: |
|
| d. |
try: |
10 points
Question 3
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: |
|
| b. |
try: |
|
| c. |
try: |
|
| d. |
try: |
10 points
Question 4
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
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 |
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
Chapter 08 Python Assignment: Question 1-5 Please I need help in my python course. Question 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? 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 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 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 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(): 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 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...
Hello, In Python Enhance the prior assignment by doing the following 1) Create a class that contain all prior functions MyLib # This function adds two numbers def addition(a, b): return a + b # This function subtracts two numbers def subtraction(a, b): return a - b # This function multiplies two numbers def multiplication(a, b): return a * b # This function divides two numbers # The ZeroDivisionError exception is raised when division or modulo by zero takes place...
PYTHON CODING HELP: BELOW ARE THE STEPS I NEED HELP WITH PLEASE. :) First create a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots ... and have it be in the same directory as the Python program you are coding for this assignment. IMPORTANT: Your program should work with any size file. It should work with 100 items listed or with no items in the file! Write a Python program that ... 1....
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) { 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...