Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
thumb_up100%
Write a PYTHON code with at least 2 functions (one should call the other).
The function which is called by the first function should also be able to be called directly.
Execute these functions with various parameters such that you can demonstrate the following:
- Each function should have some debug code so you can trace calls to the functions and activity within the functions.
- Each should handle at least 2 types of exceptions (both shouldn't handle the same exceptions).
- The function called by the first one should, at some point, generate a division by zero error, but should NOT handle this error.
- The function that calls the division by zero function should handle a division by zero error.
- Catch one error and raise a different one.
- Have some finally code (perhaps with some debugging output)
Demonstrate & explain:
- call the division by zero function both from your main program and from the other function. show that the exception isn't handled by the function itself but by the other function or the main program.
- run your code with examples which test each exception handler is working.
- your debugging output should make it easy for you to identify the flow of your code (what function is being called at any given moment)
If you're handling exceptions properly, you should be able to have a single program that runs through all the permutations required without being terminated by Python.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a function that returns the result of the following expression: (x² + y²) / z² It should throw an error message string if division by zero occurs. Write a main () that prompts the user for three integers, then passes those three integers (in order) to the function you wrote for assignment 1. Make sure you have an exception handler. Belt-and-suspenders time! Update main () so that it also checks the values input by the user to ensure that division by zero doesn't occur and the user is prompted repeatedly until they enter legal values.arrow_forwardProgram Requirements:You will develop a program capable of encrypt and decrypting text using Caesar cipher. In order to do this, you will be required to implement several functions, specified in the template provided.Once complete, your programs main() method should do the following:1. Prompt users to select a mode (encrypt or decrypt).2. Check if the mode the user entered is valid. If not, continue to prompt the user until a valid mode is selected.3. Prompt the user for the message they would like to encrypt or decrypt.4. Encrypt or decrypt the message as appropriate and print the output.5. Prompt the user whether they would like to encrypt or decrypt another message.6. Check if the user has entered a valid input (y/n) If not, continue to prompt the user until they enter a valid response. Depending upon the response you should either:a. End the program if the user selects no.b. Proceed directly to step 2 if the user says yes.You should use a loop to keep the programming running if the…arrow_forwardC++ You did this way back in Unit 1! But now all of your RomanNumber code is wrapped up in a class, so the "main" program is short and sweet. As before, write a program that accepts entries from the user. If it's an integer, convert to Roman Number and display. If it's a Roman Number, convert to integer and display. If it's neither, thrown an exception and continue to process The action to take here will be to display an error message If the entry is 0 or O (The digit 0 (zero) or the letter O) exit and state how many conversions were done of each type (integer to Roman and Roman to integer) and how many exceptions were thrown. As I said, the main program will be short and sweet. Provide your .cpp code and a screen shot of your program in action. Enter twelve conversions - four integer to Roman, four Roman to integer, and two of each in which the input is invalid so that I can see the exceptions. The thirteenth and final entry will be 0 or O.arrow_forward
- please fix the issue hihlighted in yellow and please check my code. In python language: Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError and output an exception message. Use another except block to catch any ValueError caused by invalid input and output an exception message. Note: ZeroDivisionError is thrown when a division by zero happens. ValueError is thrown when a user enters a value of different data type than what is defined in the program. Do not include code to throw any exception in the program. Ex: If the input of the program is: 15 3 the output of the program is: 5 Ex: If the input of the program is: 10 0 the output of the program is: Zero Division Exception: integer division or modulo by zero Ex: If the input of the program is: 15.5 5 the output of the program is: Input Exception: invalid literal for…arrow_forwardwrite a propram has a exception class named “Exception” that must inheritfrom the C++ runtime_errorclass.This class will capture the error case for a variable price when it is negative.For example, if the user tries to create with a variable price -1, it will generate an exception and this class should capture the reason and the error value, then print:Error: Invalid price. Ignored.arrow_forwardPYTHON: Given a main program that searches for the ID or the name of a student from a dictionary, complete the find_ID() and the find_name() functions that return the corresponding information of a student. Then, insert a try/except statement in main() to catch any exceptions thrown by find_ID() or find_name(), and output the exception message. Each entry of the dictionary contains the name (key) and the ID (value) of a student. Function find_ID() takes two parameters, a student's name and a dictionary. Function find_ID() returns the ID associated with the student's name if the name is in the dictionary. Otherwise, the function throws a custom exception type, StudentInfoError, with the message "Student ID not found for studentName", where studentName is the name of the student. Function find_name() takes two parameters, a student's ID and a dictionary. Function find_name() returns the name associated with the student's ID if the ID is in the dictionary. Otherwise, the function throws a…arrow_forward
- Solve the problem in C++ (HexFormatException)Implement the hex2Dec function in Programming Exercise 16.1 to throw a HexFormatException if the string is not a hex string .Define a custom exception class named HexFormatException. Write a test program that prompts the user to enter a hex number as a string and displays the number in decimal. If the function throws an exception, display "Not a hex number".arrow_forwardQuestion 22 Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError and output an exception message. Use another except block to catch any ValueError caused by invalid input and output an exception message. Please do it ONLY in Python Language also inlcude the input and output screenshotarrow_forwardTrue or False We can define a custom generic exception.arrow_forward
- This code is only for python. this is a game- transfer rings there are 3 problems which you are solving: A: failed transfer - make sure the progam dont take more than what the user inputed by raising an exceptionB: codE the trade_money function C: if sonic doesnt have as much as the user inputed, there will be an error pop up 'ERROR TRADE FAILED'. make it so the progam can run normally rather than turning it down. CODE: class user:def __init__(self, name, initial_money):self.name = nameself.money = initial_moneydef give_money(self, amount):self.money = self.money + amountdef take_money(self, amount):# Part A: Raise an exception as appropriateself.money = self.money - amountdef print_users(users):total_money = 0for user in users:print(f'{user.name:s} has {user.money:d} rings')total_money = total_money + user.moneyprint(f'There are a total of {total_money:d} rings')# B: code the trade_money functionsonic = user('sonic', 80)tails = user('tails', 20)print_users([sonic,…arrow_forwardpls help asnwer this code in c++arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education