Python Forum
I am asking for a review of my homework to confirm I completed all steps
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am asking for a review of my homework to confirm I completed all steps
#1
#assignment instructions create 2 test cases that will trap the errors



# This program is a code of Functions for addition, subtraction, multiplication, and division
def Add():
    print (var1+var2)
def Subtract():
    print (var1-var2)
def Multiply():
    print (var1*var2)
def Divide():
    print (var1/var2)

def main():
    print("Welcome to my calculator")

# The exception below restarts the program if user doesn't enter an interger instead of showing an error.

    try:
                range1 = int(input('Enter Low Range:'))
                range2 = int(input('Enter High Range:'))
                var1 = int(input('Enter Your First Number: '))
                var2 = int(input('Enter Your Second Number: '))

    except ValueError:
                print("Please enter intergers only, re-enter.")
                main()

    if var1 < range1 or var2 > range2 or var1 > range2 or var2 < range1:
                print("Your number is not within the correct range, please try agian")

    else:

                print('{} + {} = '.format(var1, var2))
                print(var1 + var2)
                print('{} - {} = '.format(var1, var2))
                print(var1 - var2)
                print('{} * {} = '.format(var1, var2))
                print(var1 * var2)

#This is an exception to entering "0". By doing so, we will no longer get an error and get to restart the program.

    try:
            print('{} / {} = '.format(var1, var2))
            print(var1 / var2)
    except ZeroDivisionError:
            print("Zero is not allowed")
            again = input("Would you like to calculate again? y/n")
            if again == "y" or \
                again == "Y":
                main()
            else:
                print("Thanks for using my calculator!")

            again = input("Would you like to calculate again? y/n")
        
            if again == "y" or \
                again == "Y":
                main()
            else:
                print("Thanks for using my calculator!")
main()

#These are my ranges
x=0
y=1000


def IsinRange(number):

    if x <= number <= y:
        print('The number {} is in range ({}, {})'.format(number, x, y))
    else:
        print('The number {} is not in range ({}, {})'.format(number, x, y))

testNumbers = [int(input("Enter any number!:"))]

for a in testNumbers:
      IsinRange(a)
Reply


Messages In This Thread
I am asking for a review of my homework to confirm I completed all steps - by mcgraw927 - Jun-23-2020, 03:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Requesting homework help and maybe a little code review… JonnyEnglish 0 1,620 Jan-16-2020, 04:34 PM
Last Post: JonnyEnglish

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020