示例#1
0
def addition():
    num1 = request.args.get('num1')
    num2 = request.args.get('num2')
    if num1 is None:
        num1 = 0
    if num2 is None:
        num2 = 0
    return render_template('addition.html',
                           num1=num1,
                           num2=num2,
                           addition=functions.addition(float(num1),
                                                       float(num2)))
from functions import addition, school_grading, triangle_area, division, large_equal
large_equal()
addition()
school_grading()
triangle_area()
division()
示例#3
0
def test_addition():
    assert functions.addition(1, 1) == 2
    assert functions.addition(1, 1) != 1
示例#4
0
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.

"""
'/n'
import functions

#a = int(input("Please provide a number:   "))
#b = int(input("Please provide another number:   "))

a = 10
b = 20

output = functions.addition(a, b)

print(f"The answer of the sum is: {output}")
示例#5
0
    def newClient(self, connection, client_address, port):
        print(timePrintout() + "  New Client: thread created")

        try:
            print(timePrintout() + "  Connection from", client_address, ":",
                  port)

            # Receive the data in small chunks and retransmit it
            while True:
                data = connection.recv(4096)

                if len(data) != 0:
                    message = Segment.unpack(data)
                    #message.print()
                    print(message.time() + '  Received: ' + message.printout())

                    token = message.id
                    numberA = int(message.numberA)
                    numberB = int(message.numberB)

                    if message.operation == OPERATION.id:
                        token = random.randint(100, 1000)
                        connection.sendall(
                            Segment(OPERATION.id, True, token, time.time(), "",
                                    "", "").pack())
                    elif message.operation == OPERATION.addition:
                        result = functions.addition(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.addition, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.addition, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.subtraction:
                        result = functions.subtraction(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.subtraction, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.subtraction, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.multiplication:
                        result = functions.multiplication(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.multiplication, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.multiplication, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.division:
                        result = functions.division(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.division, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.division, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.exponentiation:
                        result = functions.exponentiation(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.exponentiation, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.exponentiation, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.negation:
                        result = functions.negation(numberA)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.negation, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.negation, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.root:
                        result = functions.root(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.root, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.root, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.combination:
                        result = functions.combination(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.combination, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.combination, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.factorial:
                        result = functions.factorial(numberA)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.factorial, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.factorial, True, token,
                                        time.time(), 0, 0, result).pack())
                    else:
                        print(timePrintout() +
                              "  Error occured: Wizard must be stopped!")

                    # break

        finally:
            # Clean up the connection
            connection.close()
示例#6
0
def test_addition():
    x = functions.addition(3, 4)
    assert x == 7
import functions

for i in range(0, 1000000):
    functions.addition(1, 2)

for i in range(0, 1000000):
    functions.subtraction(2, 1)

for i in range(0, 1000000):
    functions.divide(1, 1)

lst = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
for i in range(0, 1000000):
    functions.iterate('z', lst)
示例#8
0
import functions

a1 = functions.addition(1, 2)
print(a1)

import random as r
randomNumber = r.randint(1, 5)
print(randomNumber)

from math import sqrt, cos, sin
temp = sqrt(16)
print(temp)

# import moduleName
# import moduleName as anotherName
# from moduleName import functionName
示例#9
0
文件: test.py 项目: Weggr/testspython
def test_addition():
    assert addition(3, 4) == 7
    assert addition(-3, 4) == 0
示例#10
0
import functions

a = functions.addition(1, 2, 3)
print("Added value is :", a)
示例#11
0
import functions as f
a = f.addition(1, 2, 3)
print("Added value is :", a)