Explain the use of lists and dictionaries in Python programming Course Outcome: 6. Summarize the use of files and exceptions in Python programm
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.
https://www.w3schools.com/python/gloss_python_raise.asp
https://www.programiz.com/python-programming/exception-handling
"""
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
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
