예제 #1
0
def prob3(a,b):
    """Calculate and return the length of the hypotenuse of a right triangle.
    Do not use any methods other than those that are imported from the
    'calculator' module.
    
    Parameters:
        a (float): the length one of the sides of the triangle.
        b (float): the length the other nonhypotenuse side of the triangle.
    
    Returns:
        The length of the triangle's hypotenuse.
    """
    leg = calc.root(calc.add(calc.square(a),calc.square(b)))
    return leg
예제 #2
0
def prob3(a, b):
    """Calculate and return the length of the hypotenuse of a right triangle.
    Do not use any methods other than those that are imported from the
    'calculator' module.
    
    Parameters:
        a (float): the length one of the sides of the triangle.
        b (float): the length the other nonhypotenuse side of the triangle.
    
    Returns:
        The length of the triangle's hypotenuse.
    """
    leg = calc.root(calc.add(calc.square(a), calc.square(b)))
    return leg
예제 #3
0
def printResult(op1, op2):
    if menunumber == "1":
        print("\t\t", op1, "+", op2, "=", calculator.plus(op1, op2))

    elif menunumber == "2":
        print("\t\t", op1, "-", op2, "=", calculator.minus(op1, op2))

    elif menunumber == "3":
        print("\t\t", op1, "*", op2, "=", calculator.multi(op1, op2))

    elif menunumber == "4":
        print("\t\t", op1, "/", op2, "=", calculator.divide(op1, op2))

    elif menunumber == "5":
        print("\t\t", op1, "//", op2, "=", calculator.quotient(op1, op2))

    elif menunumber == "6":
        print("\t\t", op1, "%", op2, "=", calculator.remainder(op1, op2))

    elif menunumber == "7":
        print("\t\t", op1, "**", op2, "=", calculator.square(op1, op2))
예제 #4
0
def index():
    result = 0
    error = ""
    if request.method == "POST":
        result = 0
        number = request.form.get("number")
        text = f"'{number}', Ist Typ: {type(number)}, Ist leer: {not number}, Ist eine Zahl: {number.isdigit()}"

        if not number:
            error = "Bitte eine Zahl eingeben"
        else:
            try:
                test = square(float(number))
                string = f"{number} squared is {test}"
                result = f"{string}!"
                history.append(string)
            except ValueError:
                error = "Please Type In A NUMBER!"
                result = "error"
    return render_template("index.html",
                           result=result,
                           history=history,
                           error=error,
                           text=text)
예제 #5
0
def test_square(x, x2):
    assert calculator.square(x) == x2
예제 #6
0
print(sum(3, 5))
8
만약 모듈에 정의된 모든 변수, 함수, 클래스를 호출하려면 어떻게 할까요?

from calculator import sum, difference, product, square
위와 같은 방식으로 호출할 수도 있습니다만, 모듈에서 쓰고 싶은 변수, 함수, 클래스가 100개 이상이라면 그것들을 일일이 입력하는 것은 바보 같은 일이겠죠?

*를 쓰면, 모듈 안에 정의된 모든 변수/함수/클래스를 불러올 수 있습니다.

from calculator import *

print(sum(3, 5))
print(difference(3, 5))
print(product(3, 5))
print(square(3))
8
-2
15
9
그러나 모듈 파일의 일부만 사용하려고 할 때, *를 쓰는 것은 좋지 않은 습관(practice)입니다. 100개의 함수가 정의되어 있는데 4개만 사용하려고 한다면, *를 이용하기보다 하나 하나 직접 호출하는게 낫습니다. 스스로 상황 별로 적절히 잘 판단하여, 하나하나 직접 호출할지, 아니면 모듈에 정의된 모든 것을 호출할지 결정해야 합니다.

randint 함수와 uniform 함수
randint는 두 정수 사이의 어떤 랜덤한 정수(난수)를 리턴시켜주는 함수입니다. randint는 파이썬에 기본적으로 깔려있는 random이라는 모듈에 정의되어 있습니다. 따라서 이 함수를 사용하기 위해서는 random이라는 모듈로부터 불러와야 합니다.

from random import randint
함수를 불러오는 방법에 대해 봤으니, 이제 사용하는 방법에 대해 알아보겠습니다.

# a <= N <= b인, 랜덤한 정수(난수) N의 값을 리턴시켜준다.
randint(a, b)
x에 randint(1, 20)을 지정하고 출력해봅시다. 프로그램을 실행하면 1과 20사이의 랜덤한 정수가 콘솔에 출력됩니다. 다시 실행하면 또 랜덤한 정수가 콘솔에 출력됩니다.
예제 #7
0
파일: test.py 프로젝트: jojou12/sanju
import calculator,area1
print("hello")
calculator.add(10,20)
calculator.circle(10)
calculator.square(2)
from calculator import*
circle(10)
예제 #8
0
def get_sqr():  #variable name cahnges from test_square to get_sqr
    output = square(15)  #value changes from 3 to 15
    assert output == 225  #square become 225
예제 #9
0
def test_square():
    results = square(4)  #changing the value of square
    assert results == 16
예제 #10
0
def test_square():
    assert square(2) == 4
예제 #11
0
def test_square(arg, eo):
    assert square(arg) == eo
예제 #12
0
 def test_square(self):
     assert 100 == calculator.square(10)
예제 #13
0
 def test_square_0(self):
     """Test."""
     assert 0 == calculator.square(1, 1)
     assert 9 == calculator.square(3, 2)
예제 #14
0
def test_square():
    results = square(3)
    assert results == 9
예제 #15
0
def test_square():
    est = calculator.square(2)
    ex = 2**2
    assert est == ex
예제 #16
0
 def test_squared(self):
     assert 25 == calculator.square(5)
예제 #17
0
 def Square(self, request, context):
     response = calculator_pb2.Number()
     response.value = calculator.square(request.value)
     return response