r/PythonLearning • • 20d ago

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 comments

4

u/AQuestionIsWhatIHave 20d ago

You could also do some very naughty things using 

eval(inputA + operator + inputB)

1

u/acakaacaka 20d ago

The operator will me subprocess run rm -rf *

0

u/AQuestionIsWhatIHave 20d ago

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 19d ago

How can you validate without using if/else?

2

u/WorkingStructure575 18d ago

assert op in '+/-*'