Chat with us, powered by LiveChat Explain the use of lists and dictionaries in Python programming Course Outcome: 6. Summarize the use of files and exceptions in Python programm - Wridemy

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

    Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

    Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

    Do you need an answer to this or any other questions?

    About Wridemy

    We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

    How It Works

    To make an Order you only need to click on “Place Order” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

    Are there Discounts?

    All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

    Hire a tutor today CLICK HERE to make your first order