Apr-20-2017, 04:56 PM
Hello, I'm so stuck with my assignment. So far I have built the program, I just need help with dividing by the zero exception? What is that exactly I keep getting mixed results from different websites. And how do I implement the sys.exit(function) into my program?
1) The sys.exit( ) function can be used to exit the program from any code location. The sys module (a python library) can be imported into your program with an import statement at the top of your code file.
2) If the user chose division, use exception handling to detect a possible divide by zero exception. If an exception occurs, print out an appropriate error message and exit the program gracefully.
1) The sys.exit( ) function can be used to exit the program from any code location. The sys module (a python library) can be imported into your program with an import statement at the top of your code file.
2) If the user chose division, use exception handling to detect a possible divide by zero exception. If an exception occurs, print out an appropriate error message and exit the program gracefully.
print("Select An Operator") print("Addition: +") print("Subtraction: -") print("Multiplication: *") print("Division: /") operator = input("Enter Choice (+,-,*,/:) ") number = int(input("Please enter a number: ")) number2 = int(input("Please enter a second number: ")) if operator == '+': print(number + number2) elif operator == '-': print(number - number2) elif operator == '*': print(number * number2) elif operator == '/': print(number / number2) else: error