r/PythonLearning • • Sep 17 '26

Help Request any clue how to do this?

Post image

im on my first year of learning python in school is this even possible??

25 Upvotes

34 comments sorted by

View all comments

Show parent comment

4

u/AQuestionIsWhatIHave Sep 17 '26

You could also do some very naughty things using 

eval(inputA + operator + inputB)

1

u/acakaacaka Sep 17 '26

The operator will me subprocess run rm -rf *

0

u/AQuestionIsWhatIHave Sep 17 '26

Someone is getting coal for Christmas... 

You can validate the a/b inputs with isnum() and the operator with ... in set("+-*/")

1

u/Ok_Form2940 Sep 18 '26

How can you validate without using if/else?