Module: (Python) Arithmetic expressions


Problem

1/6

Arithmetic expressions

Theory Click to read/hide

Recall the assignment operator. General view can be written in this way

variable = expression
The expression on the right side of the assignment operator allows you to calculate the values of variables using various formulas.

What expression can contain
• integers and real numbers (in real numbers, the integer and fractional parts are separated by a dot, not a comma, as is customary in mathematics)
• signs of arithmetic operations:  
+ Addition
- subtraction
* Multiplication
/ Division
** exponentiation

•calls to standard functions (we give only part of a large set. All mathematical functions are described in the math library, which must be connected using the import math  string)
 abs(n) module of integer n
 math.fabs(x) modulus of a real number x
 math.sqrt(x) the square root of the real number x
 math.pow(x,y) computes x to the power of y

• parentheses to reorder

When changing the values of variables, it is convenient to use a shorthand notation
Full string Short string
a = a + b a +=  b
a = a - b a -=  b
a = a * b a *=  b
a = a / b a /=  b

 

Problem

Supplement the program that calculates the value of the variable y by the formula:
y=(1-x2+2,5x3+x4)2

The value of the variable x is integer and is set from the keyboard.
Output the calculated value of the variable y on the screen