Python is a general-purpose programming language. This means that you can create various types of software in it: write web applications, scripts to improve the operation of the system, analyze large data sets, create artificial intelligence. There are really many applications for Python.
If you do not have any programming experience, Python is a good choice for a start: it's an easy language for beginners, but at the same time, it offers great possibilities. It is designed so that the programmer does not have to "fight the syntax", he only solves problems. Python is used by small, medium and large companies: Google uses this language extensively in its search engine and on YouTube. Instagram and Pinterest are written entirely in Python!
Python's history speaks best for its potential and flexibility. When it was created in 1991, many branches of computer science, in which it is most extensively used today, were only starting to develop. Apart from a handful of enthusiasts, nobody seriously thought about them!
Each program - regardless of the language used - must store the data it will use. This may be, for example, the user's name or the price of the purchased movie DVD. We store data in special constructions which we call variables.
In Python, variables are defined as follows:
Let's start with the explanation from the ‚#‘ sign: it indicates a comment and it's for describing the code. Everything you see in the line of code after this sign will not be executed by the computer.
Please note the following:
In the above example, we have defined the following three variables:
The simplest way to imagine a variable is a box with a label. We can store different items in the box - in our case, various information. In Python, first we write the name of the "label", and after the equality sign - the contents of the "box". We can replace the contents in the box, e.g.
From now on, the variable user stores the value "Darth Vader".
Important note: if you do not declare a variable - you can not use it! When trying to use a variable that is not defined, you will get an error!
Call it as you want. :) Although, as everywhere, Python programmers have certain rules:
Variables can store different data. The most popular are:
Note that the string is stored in quotes.
A number can be an integer (abbreviated as int) or a floating point number (float)
It can take two values:
(both values must necessarily be capitalized).
Sometimes we want the variable value to be empty, just like a box can be empty. Zero is not a solution here, because zero is an int value. This value is None (also capitalized).
The data exists to inform the user. We can therefore display them on the screen with the print() statement.
See an example of communication with a user
Define a product variable, assign the value "Computer" to it. Then define a net_price variable - assign the value of 1500 to it. Display a message on the screen with the name and the net price of the product.
Need a hint?
Look at the code written in task 2. Why doesn't it work? Correct it and run it. Read the error message that will be displayed carefully, you will find instructions there.
If you are still having problems, see task 1.
Need a hint?
Look at the task code of the third task. There are four variables of the logical type and one numeric variable. Each of them corresponds to a particular kind of weather. Look out the window, check the weather and set the variables accordingly. Run the program.