【发布时间】:2017-11-27 19:38:32
【问题描述】:
所以我对编程有点陌生,我正在寻求一些帮助。我正在制作一个图形计算器,并希望用户使用 x 输入一个等式,例如 (x + 3) 或 (x^2 + 3x + 4)。我最近发现了 lambda 函数,想知道是否有办法将变量传递给它,以便使用用户方程获取绘图点。我计划使用 for 循环将新值传递给方程。如果您对如何完成我的图形计算器有任何其他建议,请随时通知我。到目前为止,我的代码只是用户浏览我的程序的一种方式。这是我的代码:
def main():
while True:
response = menu()
if response == "1":
print("enter an equation in the form of mx + b")
equation = (input())
print(coordinates(equation))
elif response == "2":
print("enter a value for x")
x = input()
print("enter a value for y")
y = input()
elif response == "0":
print("Goodbye")
break
else:
print("please enter '1' '2' or '0'")
def menu():
print("Graphing Calculator")
print("0) Quit")
print("1) Enter an equation")
print("2) Plot points")
print("Please select an option")
response = input()
return response
"""def coordinates(equation):
f = lambda x: equation
"""
if __name__ == "__main__":
main()
【问题讨论】:
-
-
还可以考虑将 Sympy 用于您的后端。
标签: python variables lambda calculator graphing