Hello! Today i will be teaching how to make a calculator!
I am going teach the Eval function way.This is my method personally, Its very easy and short
First you prompt the user for input like this:input("Expression: ")
input("Expression: ")
Lets assign that to a variable:x = input("Expression: ")
x = input("Expression: ")
EDIT: Be aware that eval excutes any python code that is given. Making eval unsafe.Now time to actually solve it:eval(x)
eval(x)
Lets print that out:print(eval(x))
print(eval(x))
If you want you can assign it to a variable:a = eval(x)
a = eval(x)
And now we can add the finishing touches, Such as while loop and a welcome.
Total code:print("Welcome! Type any expression and i will solve it")while True:x = input("> ")a = eval(x)print(a)And thats it!
print("Welcome! Type any expression and i will solve it")
while True:
x = input("> ")
print(a)
hrrrmmmmmmmm
Well this is just a guide to using eval (kinda (not really)) this will execute any python code you give it
yo
How to make a calculator in python!
Hello! Today i will be teaching how to make a calculator!
I am going teach the Eval function way.
This is my method personally, Its very easy and short
First you prompt the user for input like this:
input("Expression: ")
Lets assign that to a variable:
x = input("Expression: ")
EDIT: Be aware that eval excutes any python code that is given. Making eval unsafe.
Now time to actually solve it:
eval(x)
Lets print that out:
print(eval(x))
If you want you can assign it to a variable:
a = eval(x)
And now we can add the finishing touches, Such as while loop and a welcome.
Total code:
print("Welcome! Type any expression and i will solve it")
while True:
x = input("> ")
a = eval(x)
print(a)
And thats it!
hrrrmmmmmmmm
Well this is just a guide to using eval (kinda (not really)) this will execute any python code you give it
yo