def run(): print( "This program will help with simple calculations. What do you want to do?" ) print("1 - add numbers") print("2 - subtract numbers") print("3 - multiply numbers") print("4 - divide numbers") answer = input(">> ") a = int(input("A=")) b = int(input("B=")) if answer == "1": result = add(a, b) print("Result = " + str(result)) if answer == "2": result = subtract(a, b) print("Result = " + str(result)) if answer == "3": result = multiply(a, b) print("Result = " + str(result)) if answer == "4": result = divide(a, b) print(f"{result}")
def test_division(self): self.assertEqual(cal.divide(10, 5), 2) self.assertEqual(cal.divide(10, -5), -2) self.assertEqual(cal.divide(-1, 1), -1) self.assertEqual(cal.divide(-1, -5), 1 / 5) # self.assertRaises(ZeroDivisionError, cal.divide, 4, 0) # self.assertRaises(ZeroDivisionError, cal.divide, 4, 2) with self.assertRaises(ZeroDivisionError): cal.divide(5, 0)
import cal print("Calculator") print("***********") print( "Press A to add \nPress s to subtract \nPress m to multiply \nPress d to divide" ) a = input("enter your choice :") if a == 'A' or a == 'a': cal.add() elif (a == 's' or a == 'S'): cal.subtract() elif (a == 'M' or a == 'm'): cal.multiply() elif (a == 'd' or a == "D"): cal.divide() else: print("enter valid option")
def testDivideFunction(self): self.assertEqual(divide(6, 3), 2)
def testDivideFunction(self): self.assertEqual(divide(100,10), 10)
def test_divide(self): self.assertEqual(cal.divide(10, 5), 2, 'message') self.assertEqual(cal.divide(10, -5), -2, 'message') self.assertRaises(ValueError, cal.divide, 10, 0) with self.assertRaises(ValueError): cal.divide(10, 0)
# -*- coding: utf-8 -*- """ Created on Thu Feb 15 02:01:43 2018 @author: sharda """ import cal print("select operation:") print("1.add") print("2.subtract") print("3.multiply") print("4.divide") choice=input("enter choice(1/2/3/4):") num1=int(input("enter first num:")) num2=int(input("enter second num:")) if choice=='1': print(num1,"+",num2,"=", cal.add(num1,num2)) elif choice=='2': print(num1,"-",num2,"=",cal.subtract(num1,num2)) elif choice=='3': print(num1,"*",num2,"=",cal.multiply(num1,num2)) elif choice=='4': print(num1,"/",num2,"=",cal.divide(num1,num2)) else: print("its not present")
import cal number = 10 number = 2 print(cal.add(10, 2)) print(cal.subtract(10, 2)) print(cal.multiplied(10, 2)) print(cal.divide(10, 2))