Share your repls and programming experiences

← Back to all posts
a calculator!
AilbheCunningha (6)

really helpful piece of equipment you can use for maths and science or even just playing around with numbers!! please like and comment

from Ciara and Ailbhe xx

Commentshotnewtop
slip1244 (253)

print("answer: " + str(eval(input("enter an equation to evaluate: "))))

Haaruun (95)

eval ok, if you use it properly @MarcusWeinberger

MarcusWeinberger (589)

@Haaruun eval never okay, better alternatives. for any task. i dare u challenge me, please im bored

Haaruun (95)

whats wrong with eval? i'll find a sulution to all of them

MarcusWeinberger (589)

@Haaruun okay then nice when would you ever need to use eval and couldn't use something better maybe more secure/robust

Haaruun (95)

And what are the security holes? @MarcusWeinberger

Haaruun (95)

You can add a context object to it to isolate it form your program if you want, import math; eval("math.pi", {"math":math}) @MarcusWeinberger

MarcusWeinberger (589)

@Haaruun with using user input. it can be messed with and the program could be exploited

MarcusWeinberger (589)

@Haaruun and that's not what i meant. i mean when u have to use eval with input to get something dynamic or whatever like op did

Haaruun (95)

Thats why you can control the context so they dont ruin the rest of the code @MarcusWeinberger

Haaruun (95)

And just use proper error handling like the rest of the user input you get @MarcusWeinberger

Andi_Chin (220)

@Haaruun also this is a 20 line calculator program, there's nothing to be exploited lol

AilbheCunningha (6)

of course it does we are coders ;)) you sound like my friend Joe! @thejoeman24

thejoeman24 (31)

The divided thingy doesnt work

AlexanderTarn (274)

you put in "=" instead of "+" in the input.

AilbheCunningha (6)

thanks babes!!! ill fix that now for u doll xx @AlexanderTarn