Executive Solution Overview
## **Instructions** **Course Outcome: 4. Explain the use of lists and dictionaries in Python programming** **Course Outcome: 6. Summarize the use of files and exceptions in Python programming** “”” This is the flower box, and it should be at the beginning of each assignment. You must add comments to…
Instant Solution Download
$6.99Immediate access to the full model answer, formatted citations, and rubric breakdown.
Need a Fresh Custom Paper?
Have this question answered from scratch according to your specific instructions and deadline.
Order on TutorsGallery →Assignment Prompt & Instructions
## **Instructions**
**Course Outcome: 4. Explain the use of lists and dictionaries in Python programming**
**Course Outcome: 6. Summarize the use of files and exceptions in Python programming**
“””
This is the flower box, and it should be at the beginning of each assignment.
You must add comments to your code
Program Name: Wk4_firstname_lastname.py
Student Name: Ymmas Azaba
Course: ENTD220
Instructor: My instructor
Date: Any Day
Copy Wrong: This is my work.
“””
**ASSIGNMENT**
_**You are going to enhance the prior assignment by implementing exceptions!**_
**\*\*\*\*\* You must tell me where you implemented the exception and why. *******
– Show me 2 test cases that will trap the errors.
– Sample output
– Enter first number between -10 and 20 –> add
– Error –> could not convert string to float: 'add' <<<< first trap
– Enter first number between -10 and 20 –> 10
– Enter second number between -10 and 20 –> 0
– Error –> float division by zero <<< second trap
Submission Instructions:
– Make sure that you save your code in a text file in this format.
– **W4_firstname_lastname.py**
**HINTS:**
"""
comment block
"""
# def functions
def add …
def sub…
def …
def isinrange() or checknum()
while True:
try:
## Get user inputs
## Do calculation and print results
except Exception as e:
print("Error –>",e)
continue
print thank you for using…
_**# Trapping Errors**_
# Trapping error to avoid program breaking when error occurs
# errors can be user errors or system errors
# try-except should be on the program level
# try-except gives the user a chance to correct
# the error instead of terminating the program
"""
Do I raise or return errors in Python?
Raise a python exception, and then wrap all of your self written functions in a try/except wrapper.
Return a result that indicates there was an error. As easy as returning False if it didn't work,
or returning a dictionary with an error field. What's the pro's and con's of each? Thoughts?
Never return an error in the same place as a value.
"""
def div(n1,n2):
return n1/n2
while True:
try:
fnum=float(input("Enter first number –> "))
snum=float(input("Enter second number –> "))
print("The div = ", div(fnum,snum));
break
except Exception as e:
print(“Error: “,e)
continue
Enter first number –> sam
ValueError: could not convert string to float: 'sam'
# Test 2
Enter first number –> 7
Enter second number –> 0
Leave a Reply