[英]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.