Learning Python? Trying to make a Calculator? Then Read this post. For creating an easy calculator in python you just need two lines of code and you don't need to install any other packages for that.
AND THIS IS THE CODE _
x = input("Type your equation here : ")
print("Your Answer is : ", eval(x))
So, What does this code means?
In the first line, you can see x
which is a variable and input("Type your equation here : ")
which means an input and when it prints, it's like the selected text in image given below.
And for the next line - print("Your Answer is : ", eval(x))
. The first code, which is print("Your Answer is : )
shows the text inside the quotes. And , eval(x)
Calculates the equation.
*RESULT - *
β οΈ WARNING - Always put space between every digits you put!
Top comments (3)
Thank you, but I want to add something: If you look at what eval() actually does, you will find, that it can execute code, which can be harmful in an application.
In other words, it not only can do calculations, but execute other code, too.
Oh, I see. Thank you for the information.
Any doubts ?? Comment