Workshop 1

Agenda:

  • Python (why)
  • Compiled vs interpreted languages
  • Python installation
  • IDE, environment - PyCharm, Jupyter Notebook, Atom, Sublime, VS Code
  • Yandex Contest
  • Google Colab, GitHub, replit
  • Python basics
  • Input
  • Data types
  • Arithmetics

PyCharm and Jupyter Notebook

PyCharm - IDE (Integrated Development Environment) for Python. Developer: JetBrains

Pros:

  • good for industrial development
  • integration with git
  • built-in terminal
  • free versions (for students and community)
  • etc.

Cons:

  • so bulky for data analysis task

Link: https://www.jetbrains.com/pycharm/

How to install

  1. Download exe
    win: https://www.jetbrains.com/pycharm/download/#section=windows
    mac: https://www.jetbrains.com/pycharm/download/#section=mac
  2. Install exe file
  3. Create new project
  4. Create new file in your project with file extension .py

Tutorial: https://www.youtube.com/watch?v=5rSBPGGLkW0


Jupyter Notebook - web interface for IPython (interactive python), free for use

Pros:

  • really interactive
  • so operative for data analysis
  • creating reports about your research
  • fast prototyping
  • visual results

Cons:

  • collaboration is tricky
  • versioning and code reviews are hard

Link: https://jupyter.org/

How to install

  1. Firstly install python
  2. Use command line and pip manager

write in command line:
python3 -m pip install --upgrade pip
python3 -m pip install jupyter

reopen command line and write:
jupyter notebook

Official site: https://jupyter.org/install and https://jupyter.readthedocs.io/en/latest/running.html#running


Python - how to install

win

  1. Go to https://www.python.org/downloads/ and donwload the lastest version
  2. Run .exe file
  3. Choose Install now. Choose Install launcher for all users and Add Python to PATH too.

How to check

  1. Open command line (cmd.exe)
  2. Write pip
  3. If you see help information - you install python correctly. If you see the error - please, reinstall python.

mac


Python Basics

In [0]:
#print()

print('Hello, HSE!')
Hello, HSE!
In [0]:
#it's comment!

'''

it's a comment too

'''

#hot key for comments
# win: ctrl + /
# mac: command + 
In [0]:
#variables
a = 5
a='ssdssd'
a={}

print(a)
5
In [0]:
print('it\'s', a)
print("'")
it's 5
\begin{array}{rr}\hline Escape Sequence & Meaning \\ \hline \backslash\backslash & Backslash (\backslash) \\ \hline \backslash' & Single quote (') \\ \hline \backslash" & Double quote (") \\ \hline \backslash b &ASCII\space Backspace (BS) \\ \hline \backslash f &ASCII\space Formfeed (FF) \\ \hline \backslash n &ASCII\space Linefeed (LF) \\ \hline \backslash r &ASCII\space Carriage\space Return (CR) \\ \hline \backslash t &ASCII\space Horizontal\space Tab (TAB) \\ \hline \backslash v &ASCII\space Vertical\space Tab (VT) \\ \hline \end{array}
In [0]:
#indents
i = 4
 j = 5
  File "<ipython-input-22-92195aabe723>", line 2
    j = 5
    ^
IndentationError: unexpected indent
In [0]:
#input()

my_name = input()
print('My name is', my_name)
a = int(nput())
Nick
My name is Nick

Data types

In [0]:
a = 5
type(a)
Out[0]:
int
In [0]:
b = '5'
type(b)
Out[0]:
str
In [0]:
#the same str
b1 = "5"
type(b1)
Out[0]:
str
In [0]:
c = 5.05
type(c)
Out[0]:
float
In [0]:
type(True)
In [0]:
a = int(a)
Out[0]:
5
In [0]:
str(a)
Out[0]:
'5'

Arithmetic expressions

In [0]:
2+3
Out[0]:
5
In [0]:
1234-5
Out[0]:
1229
In [0]:
'Nick'+5
'Nick' * 5 - ok
'Nick' - 'Ni' - error
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-37-e59551d3ecae> in <module>
----> 1 'Nick'+5

TypeError: can only concatenate str (not "int") to str
In [0]:
'Nick'+'ola'
Out[0]:
'Nickola'
In [0]:
a = 2
a = a*3
print(a)
6
In [0]:
b = 2
b *= 3
print(b)
6
In [0]:
length = 10
breadth = 5
area = length * breadth
print('The area is', area)
print('The perimeter is', 2 * (length + breadth))
The area is 50
The perimeter is 30
In [2]:
 
In [4]:
grade = 0.2 * A + 0.5 * H + 0.3 * S - D
print(grade)
5.9
In [5]:
#integer division
#An integer division will return the whole part from the division and discard the remainder.
5//2
Out[5]:
2
In [6]:
#modulo division
#modulo division will return the remainder of the division and discard the whole part.
5%2
Out[6]:
1
In [0]:
perimeter = 2 * (length + breadth)
area > perimeter
Out[0]:
True
In [0]:
area < perimeter
Out[0]:
False
In [0]:
area == perimeter
Out[0]:
False
In [0]:
area >= perimeter
Out[0]:
True
In [0]:
area <= perimeter
Out[0]:
False
In [ ]:
# apples sharing - 1
# divide a apples between b people evenly, leaving the remaining ones in the basket. How many apples does each person get?
a=int(input())
b=int(input())
print(b//a)
In [ ]:
#apples sharing - 2
# divide a apples between b people evenly, leaving the remaining ones in the basket. How many apples remain in the basket?
a=int(input())
b=int(input())
print(b%a)
In [ ]:
# power of two
# raise 2 to the power of n
n = int(input())
print(2**n)