Algorithms and Programming Lab Work 1
Simple Program in Python
Python is a high-level programming language created by Guido van Rossum. It is widely used for developing various types of programs, such as CLI programs, GUI applications (desktop), mobile applications, web applications, IoT, games, hacking programs, and more.
Python is also known for being easy to learn, thanks to its clean and understandable syntax.
Some features of Python include:
- A vast standard library; the Python distribution includes many ‘ready-to-use’ modules for various purposes.
- A clear and easy-to-learn syntax.
- Layout rules for source code that facilitate checking, re-reading, and rewriting code.
- Object-oriented programming.
Variables and Operators
Creating variables in Python is very simple. You just need to assign a value to a variable with the desired data type. The assignment operator is the equal sign (=).
Variables in Python are highly dynamic, meaning:
- Variables do not need to be declared with a specific data type.
- The data type of a variable can change while the program is running.
Numbers
Python recognizes several types of numbers, including integers, floating-point numbers, and complex numbers. Complex numbers can be written in the format (real+imaginaryj) or using the complex(real, imaginary)
function. The other number types can be understood from the following examples:
Source Code:variable_integer = 10
variable_float = 10.5
variable_complex = 3+14j
print(variable_integer)
print(variable_float)
print(variable_complex)
Output:10
10.5
(3+14j)
Mathematical operators function normally in Python, similar to other programming languages. Here are some notes to consider:
- Multiple variables can be assigned the same value in a single statement.
- Parentheses () are used to group operations that should be performed first.
- Dividing an integer by another integer will round down.
- An integer will be converted to a floating-point number in operations involving both integer and floating-point numbers.
- Complex numbers cannot be converted to real numbers (floating-point or integer); only their absolute value can be obtained.