Пример #1
0
    def test_mul(self):
        res = calculator.mul(3, 4)
        self.assertEqual(res, 12)

        res = calculator.mul(-3, 4)
        self.assertEqual(res, -12)

        res = calculator.mul(3.1, 2.5)
        self.assertEqual(res, 7.75)
def main():
    """Tests a few calculator function calls"""

    adds_1_2 = add(1, 2)
    print("adds 1 + 2:", adds_1_2)

    subtracts_1_2 = sub(1, 2)
    print("subtracts 1 - 2:", subtracts_1_2)

    multiplies_1_2 = mul(1, 2)
    print("multiplies 1 * 2:", multiplies_1_2)

    divides_1_2 = div(1, 2)
    print("divides 1 * 2:", divides_1_2)
def my_calc():
    # show intro text
    print('Calculator Program. Enter your mathematical expression below. '
          '\nEnter "help" for help and hit ENTER/RETURN to quit')
    # start while loop
    while True:
        cmd = input('> ')
        if cmd == "":
            break
        elif 'help' in cmd:
            print('DIRECTORY COMMANDS:')
            print('To add two numbers, enter: add')
            print('To subtract two numbers, enter: sub')
            print('To multiply two numbers, enter: mul')
            print('To divide two numbers, enter: div')
            print('To view calculator history, enter: history')
            print('To clear calculator history, enter: clear history')
            print('To quit, press enter')
            print(
                'Must type these command like so: command, space, number, space, number. i.e: div 10 2'
            )
        elif cmd == ('add'):
            cmd = cmd.split(" ")
            output = calculator.add(cmd[1], cmd[2])
            print(output)
        elif cmd == 'sub':
            cmd = cmd.split(" ")
            output = calculator.sub(cmd[1], cmd[2])
            print(output)
        elif cmd == 'mul':
            cmd = cmd.split(" ")
            output = calculator.mul(cmd[1], cmd[2])
            print(output)
        elif cmd == 'div':
            cmd = cmd.split(" ")
            output = calculator.div(cmd[1], cmd[2])
            print(output)
        elif cmd == 'clear history':
            calculator.clear_history()
            print("history cleared.")
        elif cmd == 'history':
            output = calculator.calc_history()
            print('Here is your calculator history:')
            print(output)
        else:
            print('Invalid command, please try again')
 def test_mul(self):
     assert 86 == calculator.mul(2, 43)
Пример #5
0
import calculator as cal

num1=cal.add(10,2)
print(num1)

num1=cal.sub(10,2)
print(num1)

num1=cal.mul(10,2)
print(num1)

num1=cal.div(10,2)
print(num1)
Пример #6
0
import calculator

calculator.add()
calculator.sub()
calculator.mul()
Пример #7
0
import diva

diva.Singer.song("import diva")

singer = diva.Singer()

print(singer.name)

singer.name = "aaa"

print(singer.name)

from calculator import add

print(add(3, 9))

# print(mul(3,9))

from calculator import mul

print(mul(3, 9))

import diva as d

d.Singer.song()
Пример #8
0
 def test_mul(self):
     self.assertEqual(calculator.mul(10, 5), 50)
     self.assertEqual(calculator.mul(10, -5), -50)
     self.assertEqual(calculator.mul(-10, -5), 50)
Пример #9
0
import calculator

add_result = calculator.add(10, 2)
sub_result = calculator.sub(10, 2)
mul_result = calculator.mul(10, 2)
div_result = calculator.div(10, 2)
mod_result = calculator.mod(10, 2)

print(add_result)  #=> 12
print(sub_result)  #=> 8
print(mul_result)  #=> 20
print(div_result)  #=> 5
print(mod_result)  #=> 0
Пример #10
0
""" Calculator code with import feature from other class """

import calculator
nlist=input("Enter numbers to get their sum")
nlist=[int(x) for x in nlist.split(',')]
calculator.add(nlist)
r1=calculator.add(nlist)
print("Sum is:",r1)
n1=input("Enter first number")
n2=input("Enter second number")
calculator.sub(n1,n2)
r2=calculator.sub(n1,n2)
print("Difference is:",r2)
calculator.mul(n1,n2)
r3=calculator.mul(n1,n2)
print("Product is:",r3)
calculator.div(n1,n2)
r4=calculator.div(n1,n2)
print("Quotient is:",r4)
Пример #11
0
 def test_mul(self):
     self.assertEqual(calculator.mul(2, 4), 8)
Пример #12
0
'''sab se bara faida module banane ka k ye logic chupa deta h'''
import calculator  # imported module (1st method)(ppora module uthakar le aaya)
print(calculator.add(2,
                     4))  # caculator is a module and add is function in module
print(calculator.sub(2, 4))
print(calculator.mul(2, 4))
print(calculator.div(4, 2))

from calculator import add  # 2nd method calculator k module se sirf add ka function utha kar laya
print(add(5, 5))
print(add(5, 14))

from calculator import add, sub  # 1 se ziada jitne func chahain import kara sakte hain
print(add(5, 10))
print(sub(14, 10))

import calculator as cal  # 3rd method(Aliasing) Giving short name to imported module
print(cal.add(2, 4))
print(cal.sub(2, 4))
print(cal.mul(2, 4))
print(cal.div(4, 2))

from calculator import mul as m, div as d  # aliasing on function
print(m(5, 10))
print(d(14, 28))

from calculator import *  #4th method(importing all functions exist in module)
Пример #13
0
 def test_mul_negatives(self):
     self.assertEqual(calculator.mul(-1, 12), -12.0)
Пример #14
0
 def test_mul_ints(self):
     self.assertEqual(calculator.mul(15, 10), 150.0)
Пример #15
0
'''
    this teaches you how to create your own module
    use : suppose there are a no. of functions which are used in most of files
     so you wouid not write them in every single file
     you can simply club all these commonly used functions and import the module in whicheer file reqd
'''


import calculator
import random

calculator.add(10,20,30,50)
calculator.div(100,20)
calculator.mul(10,2,3,5)

i = random.randrange(0, 10)     # random is also a module written by a deveolper
print i
            print('Here is your calculator history:')
            print(output)
        else:
            print('Invalid command, please try again')


if __name__ == '__main__':

    # just show the top 5 best roles
    counter = ygm_best_role()
    pprint(counter)
    pprint({role: count for role, count in counter.items() if count > 50})

    # just show the top 10 lines from a_new_hope_lines.txt
    sw_number_lines()
    try:
        print('\n')
        with open(os.path.join('scripts', 'a_new_hope_lines.txt'),
                  'r') as infile:
            pprint(infile.read().splitlines(False)[:10])
    except:
        # broad clause ok here while testing...just in case sw_number_lines() isn't written yet
        print('couldn\'t find "a_new_hope_lines.txt" in the "scripts" folder')

    # try out my calculator code
    calculator.add('4', '6')
    calculator.div('6', '3')
    calculator.mul('4', '5')
    calculator.sub('10', '4')
    my_calc()
Пример #17
0
         "\nEnter 1.ADD \n 2.SUBTRACT \n 3.MULTIPLY \n 4.DIVISION \n 5.MODULUS \n 6.EXIT\n"
     ))
 if (o == 1):
     a = int(input("\nEnter the first number to be added\n"))
     b = int(input("\nEnter the second number to be added\n"))
     c = cal.add(a, b)
     print("\nThe sum is ", c)
 elif (o == 2):
     a = int(input("\nEnter the first number to be subtracted\n"))
     b = int(input("\nEnter the second number to be subtracted\n"))
     c = cal.sub(a, b)
     print("\nThe difference is ", c)
 elif (o == 3):
     a = int(input("\nEnter the multiplicant\n"))
     b = int(input("\nEnter the second number to be multiplier\n"))
     c = cal.mul(a, b)
     print("\nThe product is ", c)
 elif (o == 4):
     a = int(input("\nEnter the first number to be dividend\n"))
     b = int(input("\nEnter the second number to be divisior\n"))
     c = cal.div(a, b)
     print("\nThe quoitent is ", c)
 elif (o == 5):
     a = int(input("\nEnter the first number to be dividend\n"))
     b = int(input("\nEnter the second number to be divisior\n"))
     c = cal.mod(a, b)
     print("\nThe remainder is ", c)
 elif (o == 6):
     print("\nExiting\n")
 else:
     print("\nYou have enter an invalid number.Try Again\n")
Пример #18
0
import calculator

num1=calculator.add(10,2)
print(num1)

num2=calculator.sub(10,2)
print(num2)

num3=calculator.mul(10,2)
print(num3)

num4=calculator.div(10,2)
print(num4)
Пример #19
0
import calculator
from Dog import Dog

numbers = [1,3,4,5,6]

add = calculator.add(*numbers)
  
print("add:", add)
mul = calculator.mul(*numbers)
print("multiply:", mul)
bi = Dog("Bi", 2)
bi.walk()
print(bi.age)
 def test_mul(self):
     self.assertEqual(calculator.mul(40, 2), 80)
Пример #21
0
# from calculator import (addition,
#                         subtraction,
#                         multiplication,
#                         division)

from calculator import (addition as add,
                        subtraction as sub,
                        multiplication as mul,
                        division as div)

from calculator import *

from greet import greet


num1 = 10
num2 = 20

print(
    add(num1, num2),
    sub(num1, num2),
    mul(num1, num2),
    div(num1, num2),
    sep='\n'
)

print(
    greet("Makku")
)
Пример #22
0
import calculator

print(calculator.add(2, 3))
print(calculator.sub(2, 3))
print(calculator.mul(2, 3))
print(calculator.div(2, 3))
Пример #23
0
import calculator

print(calculator.add(3, 4))
print(calculator.sub(10, 9))
print(calculator.mul(6, 10))
print(calculator.div(10, 5))
Пример #24
0
# from calculator import add

# result = calculator.add(1,2)
# print(result)

#
# from calculator import add

# result = add(1,2)
# print(result)

#
from calculator import add,sub,mul,div
# from calculator import * #*는 모두를 지정함.
result = add(1,2)
print(result)
result = sub(7,3)
print(result)
result = mul(20,11)
print(result)
result = div(10,4)
print(result)
import calculator as c

print("***********************************")
print("Calculator in Action")
print("***********************************")

a = int(input("Enter first number: "))
b = int(input("Enter 2nd number: "))

print(c.add(a, b))
print(c.sub(a, b))
print(c.mul(a, b))
print(c.div(a, b))

print("And the Random number generated is: ", c.a)
Пример #26
0
 def test_calculator(self):
     self.assertEqual(calc.sum(2, 2), 4)
     self.assertEqual(calc.sub(2, 2), 0)
     self.assertEqual(calc.mul(2, 3), 6)
     self.assertEqual(calc.div(2, 2), 1)
Пример #27
0
import calculator as calc

print(calc.add(4,2))
print(calc.sub(4,2))
print(calc.mul(4,2))
print(calc.div(4,2))
Пример #28
0
import calculator as cal

#ctrl + d 똑같은 키워드 순서대로 선택됨

num1 = cal.add(10, 2)
print(num1)

num2 = cal.sub(10, 2)
print(num2)

num3 = cal.mul(10, 2)
print(num3)

num4 = cal.div(10, 2)
print(num4)
Пример #29
0
 def test_mul(self):
     self.assertEqual(mul(2, 2), 4)
Пример #30
0
import mgs, display
from calculator import add
from calculator import mul
import area

mgs.msg_method()
display.display_method()

add(10, 20)
a = mul(10, 20)
print(a)

areacircle = area.area_circle(5)
print(areacircle)

areaS = area.area_square(5)
print(areaS)
Пример #31
0
 def test_mul2(self):
     self.assertEqual(mul(3, 2), 6)