有没有可能轻松地将每个公式与脚本链接到“一个完整的公式”,因为我必须多次这样做,每天都要添加?
我一直在编译许多我自己的python脚本来计算各种数学方程。我有超过15个脚本,我想放在一起。
我是那些只需要按一下就可以完成任务的人之一,它会自动完成任务,而不是手动完成-即使一开始需要两倍的时间。
我只是复制和粘贴到‘主’脚本,我可以变成一个.exe,但我发现我一直在改变,发现错误或使其在原始文件上更好。
from math import *
from os import system, name
import math
def clear():
if name == 'nt':
_ = system('cls')
while True:
print("Area of Circle (1)\nArea of a Parallelogram (2)\nArea of a Quadrants and Semicirlces (3)\nArea of a Rectangle (4)\nArea of a Rhombus (5)\nArea of a Trapezium (6)\nArea of a Triangle (7)\nCircumfrence of a Circle (8)\nCircumfrence of a Quadrant or Semicircle (9)\nVolume of a Cylinder (10)\nVolume of a Parallelogram Prism (11)\nVolume of a Rectangular Prism (12)\nVolume of a Rhomus Prism (13)\nVolume of a Sphere (14)\nVolume of a Trapezium Prism (15)\nVolume of a Triangle Prism (16)")
print()
choice = input("Choose Formular: ")
if choice == "1":
print("Area of a Circle")
num = float(input("Radius of Circle: "))
rud = int(input("Place of rounding: "))
ans = math.pi * num ** int("2")
print(round(ans, rud))
input("Press Enter to continue...")
clear()
发布于 2019-06-01 19:09:13
您可以导入脚本。
假设您有包含formula1.py
、formula2.py
等各个公式的文件,其中包含一个函数solve()
,它执行所有的工作。要求输入,计算,然后给出输出。然后你就可以这样做了。
import formula1, formula2, formula3
while True:
...
if choice == '1': formula1.solve()
elif choice == '2': formula2.solve()
elif choice == '3': formula3.solve()
else: print('Wrong Choice')
如果您希望您的单个文件也能正常工作,那么您可以这样编写它们:
def solve():
...
if __name__ == '__main__':
solve()
一定要注意,如果没有if __name__ == '__main__'
子句,导入文件也会运行它。
https://stackoverflow.com/questions/56406045
复制相似问题