Module: (Python) Arithmetic expressions


Problem

4 /6


Writing Arithmetic Expressions

Theory Click to read/hide

Rules for writing arithmetic expressions in a programming language

Suppose we need to calculate an expression written in mathematical form in this way:

\({2 * 17,56 ^2}\over {7 * 2,47 * 0,43}\)
 
Before writing a program that will calculate the result for us, we formulate the RULES for writing algebraic expressions in a programming language:
REMEMBER!
1. Expressions contain numbers, names of other variables, operation signs, parentheses, function names
2. Arithmetic operations and their signs (+, -, *, /, //,%,)
3. The separator of the integer and fractional parts is the point.
4. An expression is written in one in a line (linear record of expressions), characters are sequentially arranged one after another, ALL operation signs are affixed; parentheses are used

Thus, following the rules for writing arithmetic expressions, we must translate this (mathematical notation) fraction into a linear record, that is, write the fraction on one line.
Because both the numerator and the denominator are complex (that is, they contain two or more factors), then when writing to a linear form, it is necessary to take the expressions in the numerator and denominator in brackets.
Thus, a linear record of such an expression will look like this:
(2*17.56*17.56)/(7*2.47*0.43)
We will write a program to calculate this expression:
To do this, determine the input and output data

Input:  because we know all the values, then you don’t need to enter anything from the keyboard, therefore there will be no input data
Output: the program should display the result of this arithmetic expression (you can enter it into some variable, or you can immediately display the value on the screen).

We will immediately display the result of the expression without saving it in any variable.
Because if we have a fraction, then the result will be a real number
print((2 * 17.56 * 17.56) / (7 * 2.47 * 0.43))
Run the program on the computer and make sure that it produces a result equal to  82.94984330235246

After that, complete the task.
 
 

Problem

Write a program that calculates the value of an expression using a well-known formula

\({{x + y} \over {x+1} } - {{xy - 12}\over {34+x}}\)

x and y are integer type variables that are entered from the keyboard (two numbers on one line)
The program should print a single number - the result of evaluating the expression