Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, For my Week 3: Loops and Functions, ENTD220 Introduction to Python class, I created the following code: # Subject: Week 3 Assignment: Loops and

Hello,

For my Week 3: Loops and Functions, ENTD220 Introduction to Python class, I created the following code:

# Subject: Week 3 Assignment: Loops and Functions.

# Description: This is an enhancement of Wk2 Assignment to add a function for each math operation (add, div, mult, sub).

# This aplication will run forever, therefore we will request user input to continue or not.

# A IsInRange() function is created to test a value between two numbers.

# Start

# IsInRange function to test a value between two ranges

# IsInRange (lowRange,highRange,number)

# Defining IsInRange Fucntion

def IsInRange(lowRange, highRange, n):

if lowRange <= n and highRange >= n:

return True

else:

return False

# Defining main program

def main():

while True:

lowRange=int(input("Enter your Lower range number ---> "))

if lowRange >= -100:

break

print("The lowest range number cannot be lower than -100")

# While loop to check if numbers are within range input by user

while True:

highRange=int(input("Enter your Higher range number ---> "))

if highRange <= 100 and highRange > lowRange:

break;

print("The highest range number cannot be higher than 100 and lower than " ,lowRange)

# While loop if number is out of range

firstNumber=int(input("Enter your First number ---> "))

while not IsInRange(lowRange, highRange, firstNumber):

print("The first number value is outside the input range, please check the number and try again")

firstNumber=int(input("Enter your First number ---> "))

secondNumber=int(input("Enter your Second number ---> "))

while not IsInRange(lowRange, highRange, secondNumber):

print("The second number value is outside the input range, please check the number and try again")

secondNumber=int(input("Enter your Second number ---> "))

# Setting Variables

addition=firstNumber + secondNumber

minus=firstNumber - secondNumber

multiply=firstNumber * secondNumber

if secondNumber == 0:

division= "You cannot divide by Zero"

else:

division=firstNumber / secondNumber

# Printing results for the caluclations

# Print addition statement and results.

print("The result of " ,firstNumber, " + " ,secondNumber, " = " ,addition)

# Print substraction statement and results.

print("The result of " ,firstNumber, " - " ,secondNumber, " = " ,minus)

# Print multiplication statement and results.

print("The result of " ,firstNumber, " x " ,secondNumber, " = " ,multiply)

# Print division statement results and conditions.

if secondNumber == 0:

print("The result of " ,firstNumber, " / " ,secondNumber, " = " ,division)

else:

print("The result of " ,firstNumber, " / " ,secondNumber, " = " ,division)

print("Thanks for using our calculator!")

# Re-start calculator to allow user to obtain a new calculation.

while True:

answer = input("Would you like to continue looping? Please enter LOWERCASE y for Yes or LOWERCASE n for No : ").lower()

if answer == "y":

main()

elif answer == "n":

print("Thanks for using our calculator!.See you soon!")

quit()

# End of main program.

main()

*********************************

Now for Week 4: Exceptions, we are being tasked to enhance the Week 3 assignment by implementing exceptions. Please see the instructions below:

Week 4 : Exceptions

Hide Assignment Information

Instructions

ENTD220 I002 Winter 2021

Assignments Week 4 : Exceptions

# This is the flower box and it should 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

You are going to enhance the prior assignment by implementing exceptions

***** You need to tell me where you implemented the exception and why. *****

Show me 2 test cases that will trap the errors

Sample output

Use the same sample output from the prior assignment

Submission Instructions:

Make sure that you save your code in a text file in this format;

W4_firstname_lastname.py

Can you please explain? I am completely lost. Please help.

Respectfully,

Rick

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions