Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

program to calculate a Bodmas Expression like:-8/2(3-6)

+1 vote
asked Aug 2, 2019 by #question

1 Answer

0 votes
answered Aug 6, 2019 by Raghav7425 (320 points)

In Python, you can do it using eval() function which evaluates an expression(given by user) using BODMAS rule.

x=eval(input("Enter an expression\n"))
print(x)

In the terminal, enter expression as: -8/2*(3-6). Because, in any programming language you can not enter expression like this: -8/2(3-6). You need to put * before opening bracket.

This will result: 12.0

If you want result as 12, then use below expression:

x=int(eval(input("Enter an expression\n")))
print(x)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...