繁体   English   中英

是否可以使用 python 和 django 制作数学公式应用程序?

[英]Is it possible to make a maths formula app using python and django?

我一直想知道是否可以使用 python 或某种带有 django 的网站制作数学公式应用程序。 我想在每次需要时参考它,因为有大量的数学公式,我不想记住它们。 如果我可以随时参考它会更容易。

是的,这可能是可能的。 如果您想节省时间,您可以完全使用 python 作为命令行应用程序来完成。 我最近为二次方程做了一个,见下面的代码:

import math


def int_input(prompt):
    while True:
        try:
            variable_name = int(input(prompt))
            return variable_name
        except ValueError:
            print("Please enter a whole number (in digits)")


def float_input(prompt):
    while True:
        try:
            variable_name = float(input(prompt))
            return variable_name
        except ValueError:
            print("Please enter a numeric value (in digits)")


def yes_input(prompt):
    while True:
        variable_name = input(prompt).lower()
        if variable_name in ["y", "yes"]:
            return "yes"
        elif variable_name in ["n", "no"]:
            return "no"
        else:
            print("""Please enter either "y" or "n". """)


print("Quadratic Solver")

while True:

    print("Input below the values of a, b and c from an equation that is of the form : ax² + bx + c = 0")
    a = float_input('a: ')

    b = float_input('b: ')

    c = float_input('c: ')

    # calculate the discriminant
    d = (b ** 2) - (4 * a * c)

    # find two solutions
    solution1 = (-b - math.sqrt(d)) / (2 * a)
    solution2 = (-b + math.sqrt(d)) / (2 * a)

    if solution1 == solution2:
        print("There is one solution: x = {0}".format(solution1))

    elif solution1 != solution2:
        print('There are two solutions, x can be either {0} or {1}'.format(solution1, solution2))

    new_question = yes_input('New question? (y/n): ')
    if new_question == "no":
        break

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM