How to input a function ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to input a function ?

I want input a function. Example: >> Enter f (x): (x**2) + 1 >> enter interval separeted by comma: 0,1 >> Insert the number of n: 10 #This code will calculate an integral from 0 to 1 of x^2 + 1, separating this interval in 10 equal parts, using the Simpsons method. But I don't know how to input a function an use it inside my code. Could someone help me ? Thanks for your attention.

28th Jul 2018, 11:02 PM
ā–²TopGun ā–²
ā–²TopGun ā–² - avatar
1 Answer
0
use built-in eval() and exec() function refer py doc for more info
29th Jul 2018, 5:07 AM
ĐɆā±¤É†JɆ theā‚²reat
ĐɆā±¤É†JɆ theā‚²reat - avatar