Beispiel #1
0
def main():
    while True:
        try:

            needed_function = int(
                input(
                    "яку функцію ви хочете запустити? якщо факторіал 1 , квадрат натисніть 2, куб натисніть 3, квадратний корінь 4,"
                    + "\n" +
                    "кубічний корінь 5 ,логарифм 6, натуральний логарифм 7 ,десятковий логарифм 8. "
                ))
            if needed_function in range(1, 9):
                break
        except ValueError:
            print("ви ввели не ціле число")
    while True:
        try:
            n = float(input("введіть аргумент"))
            break
        except ValueError:
            print("ви ввели не дробове число")
    if needed_function == 1:
        print(fac(n))
    if needed_function == 2:
        exp2(n)
    if needed_function == 3:
        exp3(n)
    if needed_function == 4:
        root2(n)
    if needed_function == 5:
        root3(n)
    if needed_function == 6:
        while True:
            try:
                base = float(input("введіть базу логарифму"))
                if base > 0 and base != 1:
                    break
                else:
                    print("ви ввели не правильну базу")
            except ValueError:
                print("ви ввели не дробове число")
        if n > 0:
            log(base, n)
        else:
            print("не можливо знайти логарифм для даного числа")
    if needed_function == 7:
        if n > 0:
            ln(n)
        else:
            print("не можливо знайти логарифм для даного числа")
    if needed_function == 8:
        if n > 0:
            lg(n)
        else:
            print("не можливо знайти логарифм для даного числа")
Beispiel #2
0
def main():
    x = int(
        input(
            'enter 1 if you want to use exp_root \n enter 2 if you want to use factorial \n enter 3 if you want to use logarithm: '
        ))

    if x == 1:
        y = int(
            input(
                'enter 1 if you want to use exponentiation \n enter 2 if you want to use root: '
            ))
        if y == 1:
            z = int(
                input(
                    'enter 1 if you want to use exp2 \n enter 2 if you want to use exp3: '
                ))
            if z == 1:
                exponentiation.exp2(float(input('Введіть число: ')))
            elif z == 2:
                exponentiation.exp3(float(input('Введіть число: ')))
        elif y == 2:
            l = int(
                input(
                    'enter 1 if you want to use root2 \n enter 2 if you want to use root3: '
                ))
            if l == 1:
                root.root2(float(input('Введіть число: ')))
            elif l == 2:
                root.root3(float(input('Введіть число: ')))
    elif x == 2:
        factorial.fact(float(input('Введіть число: ')))
    elif x == 3:
        m = int(
            input(
                'enter 1 if you want to use log \n enter 2 if you want to use ln \n enter 3 if you want to use lg: '
            ))
        if m == 1:
            logarithm.log(float(input('Введіть основу: ')),
                          float(input('Введіть число: ')))
        elif m == 2:
            logarithm.ln(float(input('Введіть число: ')))
        elif m == 3:
            logarithm.lg(float(input('Введіть число: ')))
    while True:
        res = input('Запустити програму заново? ')
        if res == 'Так':
            main()
        else:
            sys.exit(0)
Beispiel #3
0
def main(ch):
    """
    This function is print result for the selected function 
    """
    try:
        # Here is the search and launch of the selected function
        if ch == '1':
            result = fact(int(input("Factorial for ")))
        if ch == '2':
            result = exp2(float(input("Square exponention for ")))
        if ch == '3':
            result = exp3(float(input("Cube exponention for ")))
        if ch == '4':
            result = root2(float(input("Square root for ")))
        if ch == '5':
            result = root3(float(input("Cube root for ")))
        if ch == '6':
            a = float(input("Enter a base for this logarithm: "))
            b = float(input("Enter b in this logarithm: "))
            result = log(a, b)
        if ch == '7':
            b = float(input("Enter b in this logarithm: "))
            result = lg(b)
        if ch == '8':
            b = float(input("Enter b in this logarithm: "))
            result = ln(b)
        # Here is output result
        print("Result:", result)
    except ArithmeticError:
        print("Incorrect a values")
Beispiel #4
0
def main():
    print("\nWhat function you would like to use?")
    print("1. Find factorial of number")
    print("2. Find square the number")
    print("3. Find cube the number")
    print("4. Find the root of the number")
    print("5. Find the root of a third degree number")
    print("6. Find logarithm of two numbers")
    print("7. Find natural logarithm of number")
    print("8. Find decimal logarithm of numbers")
    answer = input("Input number: ")
    if answer == "1":
        num = input_int("\nYour number: ", False)
        print("Factorial of", num, "=", factorial.factorial(num))
    elif answer == "2":
        num = input_float("\nYour number: ", False)
        print("Square of", num, "=", exponentiation.exp2(num))
    elif answer == "3":
        num = input_float("\nYour number: ", False)
        print("Cube of", num, "=", exponentiation.exp3(num))
    elif answer == "4":
        num = input_float("\nYour number: ", True)
        print("The root of", num, "=", root.root2(num))
    elif answer == "5":
        num = input_float("\nYour number: ", True)
        print("The third degree root of", num, "=", root.root3(num))
    elif answer == "6":
        a = input_int("\nYour a: ", True)
        b = input_int("Your b: ", False)
        print("Logarithm of", a, ",", b, "=", logarithm.log(a, b))
    elif answer == "7":
        num = input_int("\nYour number: ", False)
        print("Natural logarithm of", num, "=", logarithm.ln(num))
    elif answer == "8":
        num = input_int("\nYour number: ", False)
        print("Decimal logarithm of", num, "=", logarithm.lg(num))
    else:
        print("There is no option with such a number")
Beispiel #5
0
def _main():
    print('-' * 20)
    print(
        "Якщо ви хочете знайти факторіал - введіть factorial\nЯкщо корінь квадратний - введіть root2\nЯкщо кубічний - введіть root3\nЯкщо логарифм з певною основою - log\nЯкщо натуральний логарифм - введіть ln\nЯкщо логарифм з основою 10 - lg\nЯкщо квадрат - введіть exp2\nЯкщо куб числа - введіть exp3"
    )
    print('-' * 20)
    print("Якщо хочете завершити програму - введіть break")
    print('-' * 20)

    while True:
        while True:
            print('-' * 20)
            a = input("Що ви хочете обчислити?")

            if a == "break" or a == "BREAK":
                print("До побачення!!!!!!!!")
                break

            else:
                if a != 'factorial' and a != 'root2' and a != 'root3' and a != 'log' and a != 'ln' and a != 'lg' and a != 'exp2' and a != 'exp3':
                    print("Введені невірні дані.")
                    raise ValueError

                if a == "factorial":
                    b = int(
                        input(
                            "Введіть число для якого потрібно знайти факторіал: "
                        ))
                    if b < 0:
                        print("Введіть додатне число")
                        raise ValueError
                    else:
                        print("Відповідь: ", factorial.fact(b))
                elif a == "root2":
                    b = float(
                        input(
                            "Введіть число для якого хочете знайти корінь: "))
                    if b < 0:
                        print("Введіть додатне число")
                        raise ValueError
                    else:
                        print("Відповідь: ", root.root2(b))
                elif a == 'root3':
                    b = float(
                        input(
                            "Введіть число для якого хочете знайти корінь: "))
                    print("Відповідь: ", root.root3(b))
                elif a == 'log':
                    b1 = float(
                        input("Введіть число для знаходження логарифма: "))
                    if b1 < 0:
                        print("Введіть додатне число")
                        raise ValueError
                    b2 = float(input("Введіть основу для логарифма: "))
                    if b2 < 0 or b2 == 1:
                        print("Введіть додатне число")
                        raise ValueError
                    else:
                        print("Відповідь: ", logarithm.log(b2, b1))
                elif a == 'ln':
                    b1 = float(
                        input(
                            "Введіть число для якого хочете знайти логарифм: ")
                    )
                    if b1 < 0:
                        raise ValueError
                    else:
                        print("Відповідь: ", logarithm.ln(b1))
                elif a == 'lg':
                    b1 = float(
                        input(
                            "Введіть число для якого хочете знайти логарифм: ")
                    )
                    if b1 < 0:
                        print("Введіть додатне число")
                        raise ValueError
                    else:
                        print("Відповідь: ", logarithm.lg(b1))
                elif a == 'exp2':
                    b = float(
                        input(
                            "Введіть число для якого хочете знайти квадрат: "))
                    print("Відповідь: ", exponentiation.exp2(b))
                elif a == 'exp3':
                    b = float(
                        input("Введіть число для якого хочете знайти куб: "))
                    print("Відповідь: ", exponentiation.exp3(b))
Beispiel #6
0
            while True:
                try:
                    a = float(input("Enter base a(a>0, а!=1): "))
                    b = float(input("Enter b(b>0): "))
                    if a < 0 or a == 1 or b < 0:
                        continue
                    print("The logarithm is", logarithm.log(a, b))
                    break
                except ValueError:
                    continue
        elif user_input3 == 2:
            while True:
                try:
                    b = float(input("Enter b(b>0): "))
                    if b < 0:
                        continue
                    print("The logarithm is", logarithm.ln(b))
                    break
                except ValueError:
                    continue
        elif user_input3 == 3:
            while True:
                try:
                    b = float(input("Enter b(b>0): "))
                    if b < 0:
                        continue
                    print("The logarithm is", logarithm.lg(b))
                    break
                except ValueError:
                    continue
Beispiel #7
0
def main():
    print()
    print("Please, choose which function do you want to test.\n"
          "Type fact or exp2 or exp3 or root2 or root3 or ln or log or lg.")
    selected = input()
    if selected == "fact":
        n = input("Type number n: ")
        try:
            n = int(n)
            if n < 0:
                return "You entered not a natural number"
            else:
                return fact(n)
        except ValueError:
            return "You entered not a number."

    elif selected == "exp2":
        n = input("Type number n: ")
        try:
            n = float(n)
            return exp2(n)
        except ValueError:
            return "You entered not a number."

    elif selected == "exp3":
        n = input("Type number n: ")
        try:
            n = float(n)
            return exp3(n)
        except ValueError:
            return "You entered not a number."

    elif selected == "root2":
        n = input("Type number n: ")
        try:
            n = float(n)
            if n < 0:
                return "You entered not a positive number"
            else:
                return root2(n)
        except ValueError:
            return "You entered not a number."

    elif selected == "root3":
        n = input("Type number n: ")
        try:
            n = float(n)
            return root3(n)
        except ValueError:
            return "You entered not a number."

    elif selected == "log":
        a = input("Type base a: ")
        b = input("Type number b: ")
        try:
            a = float(a)
            b = float(b)
            if (b > 0) and (a > 0) and (a != 1):
                return log(b, a)
            else:
                return "a and b must be positive and a != 1."
        except ValueError:
            return "1 or more of your inputs are not a number."

    elif selected == "lg":
        b = input("Type number b: ")
        try:
            b = float(b)
            if b > 0:
                return lg(b)
            else:
                return "b must be positive."
        except ValueError:
            return "You entered not a number."

    elif selected == "ln":
        b = input("Type number b: ")
        try:
            b = float(b)
            if b > 0:
                return ln(b)
            else:
                return "b must be positive."
        except ValueError:
            return "You entered not a number."

    else:
        print("This function is not planned for testing :(")
Beispiel #8
0
def main():
    while True:
        print("--------------------------")
        print(
            'Choose the operation you want to do. Input:\n'
            '"1" for factorial;\n'
            '"2.1" for square of number, "2.2" for cube of number;\n'
            '"3.1" for square root, "3.2" for cube root;\n'
            '"4.1" for ln of number, "4.2" for lg of number, "4.3" for log of number with your base;\n'
            'anything else to stop the program.')
        ans = input("Your choice:")
        if ans == "1":
            n = int_check(input("Enter your number(must be natural):"))
            while True:
                if n <= 0:
                    print(
                        "Error: your number is not natural. Choose another number."
                    )
                    n = int_check(input("Enter your number(must be natural):"))
                else:
                    break
            print("Your factorial is:", factorial.fact(n))
        elif ans == "2.1":
            n = float_check(input("Enter your number:"))
            print("Square of your number is:", exponentiation.exp2(n))
        elif ans == "2.2":
            n = float_check(input("Enter your number:"))
            print("Cube of your number is:", exponentiation.exp3(n))
        elif ans == "3.1":
            n = float_check(input("Enter your number(must be non-negative):"))
            while True:
                if n < 0:
                    print(
                        "Can`t find square root of your number. Please, choose another number."
                    )
                    n = float_check(
                        input("Enter your number(must be non-negative):"))
                else:
                    break
            print("Square root of your number is:", root.root2(n))
        elif ans == "3.2":
            n = float_check(input("Enter your number:"))
            print("Cube root of your number is:", root.root3(n))
        elif ans == "4.1":
            n = float_check(input("Enter your number(must be non-negative):"))
            while True:
                if n <= 0:
                    print(
                        "Can`t find ln of your number. Please, choose another number."
                    )
                    n = float_check(
                        input("Enter your number(must be non-negative):"))
                else:
                    break
            print("ln of your number is:", logarithm.ln(n))
        elif ans == "4.2":
            n = float_check(input("Enter your number(must be non-negative):"))
            while True:
                if n <= 0:
                    print(
                        "Can`t find ln of your number. Please, choose another number."
                    )
                    n = float_check(
                        input("Enter your number(must be non-negative):"))
                else:
                    break
            print("lg of your number is:", logarithm.lg(n))
        elif ans == "4.3":
            a = float_check(
                input(
                    "Enter your base(must be non-negative and not equals to 1):"
                ))
            while True:
                if a < 0 or a == 1:
                    print(
                        "Can`t be base of logarithm. Please, choose another number."
                    )
                    a = float_check(
                        input("Enter your number(must be non-negative):"))
                else:
                    break
            b = float_check(input("Enter your number(must be non-negative):"))
            while True:
                if b <= 0:
                    print(
                        "Can`t be base of logarithm. Please, choose another number."
                    )
                    a = float_check(
                        input("Enter your number(must be non-negative):"))
                else:
                    break
            print("log of your number with your base is:", logarithm.log(a, b))
        else:
            print(
                "Wrong input, so work is stopped. Thank you for using this program!"
            )
            break
Beispiel #9
0
def main():
    print("MENU:")
    print("- enter 1 if you want to find factorial")
    print("- enter 2 if you want to find exponentiation(2 degree)")
    print("- enter 3 if you want to find exponentiation(3 degree)")
    print("- enter 4 if you want to find root(2 degree)")
    print("- enter 5 if you want to find root(3 degree)")
    print("- enter 6 if you want to find log")
    print("- enter 7 if you want to find ln")
    print("- enter 8 if you want to find lg")
    print()
    while True:
        variant = input()
        if variant == "1":
            print("enter the integer, which >= 0")
            while True:
                a = input()
                try:
                    a = int(a)
                    if a < 0:
                        print("invalid number")
                        continue
                    else:
                        result = factorial.fact(a)
                        print()
                        print("result:", result)
                        return result
                except ValueError:
                    print("invalid number")
        elif variant == "2":
            print("enter the number")
            while True:
                a = input()
                try:
                    a = float(a)
                    result = exponentiation.exp2(a)
                    print()
                    print("result:", result)
                    return result
                except ValueError:
                    print("invalid number") 
        elif variant == "3":
            print("enter the number")
            while True:
                a = input()
                try:
                    a = float(a)
                    result = exponentiation.exp3(a)
                    print()
                    print("result:", result)
                    return result
                except ValueError:
                    print("invalid number")   
        elif variant == "4":
            print("enter the number >= 0")
            while True:
                a = input()
                try:
                    a = float(a)
                    if a < 0:
                        print("invalid number")
                        continue
                    else:
                        result = root.root2(a)
                        print()
                        print("result:", result)
                        return result
                except ValueError:
                    print("invalid number")
        elif variant == "5":
            print("enter the number")
            while True:
                a = input()
                try:
                    a = float(a)
                    result = root.root3(a)
                    print()
                    print("result:", result)
                    return result
                except ValueError:
                    print("invalid number")         
        elif variant == "6":
            print("enter the base")
            while True:
                a = input()
                try:
                    a = float(a)
                    if a <= 0:
                        print("incorrect base")
                    elif a == 1:
                        print("incorrect base")
                    else:
                        break
                except ValueError:
                    print("incorrect base")
            print("enter the number")
            while True:
                b = input()
                try:
                    b = float(b)
                    if b <= 0:
                        print("incorrect number")
                    else:
                        result = logarithm.log(a, b)
                        print()
                        print("result:", result)
                        return result
                except ValueError:
                    print("incorrect number")    
        elif variant == "7":
            print("enter the number")
            while True:
                a = input()
                try:
                    a = float(a)
                    if a <= 0:
                        print("incorrect number")
                    else:
                        result = logarithm.ln(a)
                        print()
                        print("result:", result)
                        return result
                except ValueError:
                    print("incorrect number")                    
        elif variant == "8":
            print("enter the number")
            while True:
                a = input()
                try:
                    a = float(a)
                    if a <= 0:
                        print("incorrect number")
                    else:
                        result = logarithm.lg(a)
                        print()
                        print("result:", result)
                        return result
                except ValueError:
                    print("incorrect number")   
        else:
            print("incorrect")
Beispiel #10
0
                        "Введіть ціле додатнє число, від якого бажаєте знайти факторіал\t"
                    )))
        elif f == '2':
            print(exp2(input("Введіть число, квадрат якого бажаєте знайти\t")))
        elif f == '3':
            print(exp3(input("Введіть число, куб якого бажаєте знайти\t")))
        elif f == 'r2':
            print(
                root2(
                    input(
                        "Введіть число, корінь 2-го степеня якого бажаєте знайти\t"
                    )))
        elif f == 'r3':
            print(
                root3(
                    input(
                        "Введіть число, корінь 3-го степеня якого бажаєте знайти\t"
                    )))
        elif f == 'log':
            print(
                log(input("Введіть числа:\nоснову логарифма\t"),
                    input("та число\t")))
        elif f == 'ln':
            print(ln(input("Введіть число\t")))
        elif f == 'lg':
            print(lg(input("Введіть число\t")))
        else:
            print("Такої функції не задано")
except NameError and ValueError:
    print("Введіть правильні значення")