Beispiel #1
0
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}")
Beispiel #2
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Created by winchoo
# 2018/7/6

#Directory和Python package的区别在于Directory是空的,Python package里面有个__init__.py文件

# import cal,time
# print(cal.add(3,5))
# print(cal.sub(3,5))

#注意import cal会先执行cal.py里面的内容
#模块import做了两件事情:
#1.执行对应文件
#2.引入变量名
#如果不想使用cal.则有另外一种书写方式

from cal import add
from cal import sub
#或者
from cal import *#这里的*代表一切,但是不推荐这么使用

#结果会是加载下面的函数,因为会覆盖掉之前的函数
# def add(x,y):
#     return x+y+100

print(add(3,5))
print(sub(3,5))
Beispiel #3
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")
import cal as cl
res= cl.add(10,20)
print(res)
Beispiel #5
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))
Beispiel #6
0
 def test_int_add(self):
     self.assertEqual(calculator.add(9, 3), 12)
Beispiel #7
0
import cal as lib
def cal(a,b):
    print(a,b)
print(lib.add(1,2))
print(lib.sub(10,5))
cal(1,2)
# above method is called "aliases" import 
Beispiel #8
0
 def test_add(self):
     result = cal.add(10, 5)
     self.assertEqual(result, 15)
Beispiel #9
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))
Beispiel #10
0
# 方式1
# import cal
#
# cal.add(2,4)
# cal.mul(3,5)

# 方式2:
# x = 10
# from cal import add
# from cal import x as x_new
#
#
# add(2,5)
# print(x)
# print(x_new)

# 导入文件:重复导入,只加载一次
# from cal import add
# from cal import sub
from logger import get_logger
import cal

if __name__ == '__main__':

    print("这是一个main文件")
    get_logger("main")
    cal.add(2, 6)

    print(__name__)  # "__mian__"
Beispiel #11
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")
Beispiel #12
0
 def test_add3(self):
     self.assertEqual(cal.add(8,2), 10)
Beispiel #13
0
 def test_add2(self):
     self.assertEqual(cal.add(2,1), 7)
Beispiel #14
0
 def test_add(self):
     self.assertEqual(cal.add(10,5), 15)
import cal


a=9
b=5

c=cal.add(a,b)
print(c)
Beispiel #16
0
import numpy as np
import matplotlib.pyplot as plt
from cal import add
import json

x = [[1, 2, 3, 4], [5, 6, 7, 8]]
print(x)

a = np.array(x)
print(a)

# %matplotlib inline
x = np.linspace(0, 10, 100)
y = x ** 2
plt.plot(x, y)

# from cal import add
print(add(1, 3))

# json
x = {"name": "Name 1"}
y = json.dumps(x)
print(y)
Beispiel #17
0
 def test_add(self):
     self.assertEqual(cal.add(10, 5), 15, 'success')
     self.assertEqual(cal.add(-10, -5), -15, 'success')
     self.assertEqual(cal.add(10, -5), 5, 'success')
Beispiel #18
0
def test_add():
    assert cal.add(4,5) == 9
Beispiel #19
0
try:
    print('_'.center(50, '_'))
    print('Simple calculator'.center(50))
    print('_'.center(50, '_'))
    print('MENU'.center(50, ' '))
    print('1.add')
    print('2.sub')
    print('3.mul')
    print('4.div')
    print('5.Go back')
    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)
Beispiel #20
0
 def test_float_add(self):
     self.assertEqual(calculator.add(4.2, 3), 7.2)
Beispiel #21
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

Beispiel #22
0
 def test_int2_add(self):
     self.assertEqual(calculator.add(9, 4), 13)
Beispiel #23
0
from cal import add
result = add(1, 2)
print result
Beispiel #24
0
#Import modules 
#Import everything
# import math
# print(math.sin(0.5))

# #Import with abbreviation
# import math as m
# print(m.sin(0.5))
# print(m.pi)

#-----------------------------------------------
#Import a custom module
import message as myMsg
import cal 
#from cal import add
myMsg.echoMsg("Test echo message")

myMsg.echoMsg2("Test echo message")

print(cal.add(10,3))
#print(add(10,3))
Beispiel #25
0
 def test_add(self):
     print("test add function")
     self.assertEqual(cal.add(15, 20), 35)
Beispiel #26
0
    def add_use(self):
        result = cal.add(10,5)
        print(result)


#print(add_use(3,8))
Beispiel #27
0
def add():
    a = num(request.args.get('a'))
    b = num(request.args.get('b'))
    return str(calculator.add(a, b))
# geekyshows.py <--- Main Module

import cal as c  # Importing Cal Module

print("cal Module's variable:", c.a)  # Accessing Cal Module's Variable

c.name()  # Accessing Cal Module's Function

a = c.add(10, 20)  # Accessing Cal Module's Function
print(a)

b = c.sub(20, 10)  # Accessing Cal Module's Function
print(b)
Beispiel #29
0
 def test_add(self):
     self.assertEqual(cal.add(10, 5), 15)
     self.assertEqual(cal.add(10, -5), 5)
     self.assertEqual(cal.add(-1, 1), 0)
     self.assertEqual(cal.add(-1, -5), -6)
Beispiel #30
0
 def test_addn(self):
     assert 4 == cal.add(2, 2)
Beispiel #31
0
#from cal import *
#from cal import add
from cal import (
    add,
    sub,
)
print(add(1, 2))
print(sub(10, 5))
#print(globals())