Is there something similiar to eval but doesn't take ALL the input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is there something similiar to eval but doesn't take ALL the input?

Is there something like eval that calculates input of integers only. Because eval takes all of ur input For example: in the input i can say print("hello world") and it would print it. Im trying to make a calculator that wont take all the code they input, just integers and binary operaters +-/*. Thnx

20th Aug 2023, 4:20 PM
TheLumberHack
TheLumberHack - avatar
4 Answers
+ 6
Why not do a check for an incorrect input and inform the user to input the correct thing?
20th Aug 2023, 5:41 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
You can use an if statement or a try/catch.
21st Aug 2023, 7:21 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Thnx
21st Aug 2023, 12:10 PM
TheLumberHack
TheLumberHack - avatar
+ 1
How do i do that? With an if statement?
21st Aug 2023, 12:00 AM
TheLumberHack
TheLumberHack - avatar