Exemplo n.º 1
0
#Chuong trinh Python Calculator
#Su dung cac Module, Function
#haind
#Python

import cal

vonglap = 1
choice = 0
while vonglap == 1:
    choice = cal.menu()
    if choice == 1:
        cal.add()
    elif choice == 2:
        cal.sub()
    elif choice == 3:
        cal.mul()
    elif choice == 4:
        cal.div()
    elif choice == 5:
        vonglap = 0

print "Cam on ban da su dung chuong trinh"
Exemplo n.º 2
0
'''
    #### Python Modules ####

    -A module is a file containing Python definitions and statements.
    -A module can define functions, classes and variables.
    -A module can also include runnable code.
    -Grouping related code into a module makes the code easier to understand and use.

    ## Two Ways use Module ##
    1-The import statement.
    2-The from import Statement.

    ## The dir() function

'''

# 1-The import statement.
import cal
print(cal.add(4, 3))
print(cal.sub(500, 230))
print(cal.mul(3, 5))

# 2-The from import Statement.
from cal import add, sub
print(add(200, 500))
print(sub(200, 123))

# dir() function
print(dir(cal))
print(dir(sub))
Exemplo n.º 3
0
import cal


vonglap = 1
choice = 0
while vonglap == 1:
        choice = cal.menu()
        if choice == 1:
                cal.add()
        elif choice == 2:
                cal.sub()
        elif choice == 3:
                cal.mul()
        elif choice == 4:
                cal.div()
        elif choice == 5:
                vonglap = 0

Exemplo n.º 4
0
 choice1 = int(input("enter the choice\n"))
 try:
     if (choice1 == 1):
         num1 = int(input("enter the number1\n"))
         num2 = int(input("enter the number2\n"))
         res = cal.add(num1, num2)
         print("The result of add of two numbers", res)
     elif (choice1 == 2):
         num1 = int(input("enter the number1\n"))
         num2 = int(input("enter the number2\n"))
         res = cal.sub(num1, num2)
         print("The result of sub of two numbers", res)
     elif (choice1 == 3):
         num1 = int(input("enter the number1\n"))
         num2 = int(input("enter the number2\n"))
         res = cal.mul(num1, num2)
         print("The result of mul of two numbers", res)
     elif (choice1 == 4):
         num1 = int(input("enter the number1\n"))
         num2 = int(input("enter the number2\n"))
         res = cal.div(num1, num2)
         print("The result of div of two numbers", res)
     elif (choice1 == 5):
         break
     else:
         print("enter the correct choice")
 except NameError, details:
     print("invalid integer", details)
 except IOError, details:
     print("invalid integer", details)
 except ValueError, details:
Exemplo n.º 5
0
# import cal

from cal import add, sub, mul, div, sine

while (True):
    inp = input()
    if (inp == "stop"):
        break
    n = int(input())
    m = int(input())

    d = {
        "add": add(n, m),
        "sub": sub(n, m),
        "mul": mul(n, m),
        "div": div(n, m),
    }

    print(d[inp])

# s = add(n, m)
# sub = sub(8, 4)
# mul = mul(4, 8)
# div = div(8, 4)

# print(s, sub, mul, div)

# print(sine(90))
Exemplo n.º 6
0
import cal as c
a=9
b=7

print(c.add(a,b))
print(c.sub(a,b))
print(c.mul(a,b))
print(c.div(a,b))
Exemplo n.º 7
0
 def test_2_mul(self):
     result = cal.mul(3, 3)
     assert (result == 9), "Mul  is not coorect"