hi,
right now i'm working on a program that prints parabolic shapes on the screen.
And i want to be able to type a formule, and than i need python to understand that formule :?
I have heard from many people that this is extremely hard
But is there a way to do this?
I already made a peice of the program, it asks for the lenght of the formule, and then it asks piece by piece what characters the formule contains, and then it puts these characters in a list. But now the problem is how do i use the list as something that python can calculate :confused:
I would like it very much if someone could help me.

well, I want to be able to type in a formule, and then i need python to understand that formule, like it does in the shell, and with that i can print a parabol that is the outcome of that formule.

The formula has to follow Python syntax. For example ...

from math import *

# if the formula is y = 2.5sin(3x) - cos(2x)
# the user has to input a string like "2.5*sin(3*x) - cos(2*x)"
# so Python can evaluate it correctly
input_str = "2.5*sin(3*x) - cos(2*x)"

# now you can calculate your (x, y) data list
data_list = []
for x in range(10):
    y = eval(input_str)
    data_list.append((x, y))

print( data_list )

that script you showed, is a nice script,
but i want to be able to type in a formule, and then it calculates that, not a standard formule

that script you showed, is a nice script,
but i want to be able to type in a formule, and then it calculates that, not a standard formule

In that case you have to write a parser that converts the user's formula into something Python can calculate. Still, the user has to follow some rules.

what does {1:0.2f} means in pyhton / i know 2f means two decimals. o is space but what is 1 ?? thanks !

DON'T HIJACK OLD THREADS, Make your own! and 1 is a key.

Edited 5 Years Ago by pyguy62: n/a

This article has been dead for over six months. Start a new discussion instead.