# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# <table> <tr>
#         <td  style="background-color:#ffffff;">
#             <a href="http://qworld.lu.lv" target="_blank"><img src="..\images\qworld.jpg" width="25%" align="left"> </a></td>
#         <td style="background-color:#ffffff;vertical-align:bottom;text-align:right;">
#             prepared by <a href="http://abu.lu.lv" target="_blank"><NAME></a> (<a href="http://qworld.lu.lv/index.php/qlatvia/" target="_blank">QLatvia</a>)
#         </td>        
# </tr></table>

# <table width="100%"><tr><td style="color:#bbbbbb;background-color:#ffffff;font-size:11px;font-style:italic;text-align:right;">This cell contains some macros. If there is a problem with displaying mathematical formulas, please run this cell to load these macros. </td></tr></table>
# $ \newcommand{\bra}[1]{\langle #1|} $
# $ \newcommand{\ket}[1]{|#1\rangle} $
# $ \newcommand{\braket}[2]{\langle #1|#2\rangle} $
# $ \newcommand{\dot}[2]{ #1 \cdot #2} $
# $ \newcommand{\biginner}[2]{\left\langle #1,#2\right\rangle} $
# $ \newcommand{\mymatrix}[2]{\left( \begin{array}{#1} #2\end{array} \right)} $
# $ \newcommand{\myvector}[1]{\mymatrix{c}{#1}} $
# $ \newcommand{\myrvector}[1]{\mymatrix{r}{#1}} $
# $ \newcommand{\mypar}[1]{\left( #1 \right)} $
# $ \newcommand{\mybigpar}[1]{ \Big( #1 \Big)} $
# $ \newcommand{\sqrttwo}{\frac{1}{\sqrt{2}}} $
# $ \newcommand{\dsqrttwo}{\dfrac{1}{\sqrt{2}}} $
# $ \newcommand{\onehalf}{\frac{1}{2}} $
# $ \newcommand{\donehalf}{\dfrac{1}{2}} $
# $ \newcommand{\hadamard}{ \mymatrix{rr}{ \sqrttwo & \sqrttwo \\ \sqrttwo & -\sqrttwo }} $
# $ \newcommand{\vzero}{\myvector{1\\0}} $
# $ \newcommand{\vone}{\myvector{0\\1}} $
# $ \newcommand{\stateplus}{\myvector{ \sqrttwo \\  \sqrttwo } } $
# $ \newcommand{\stateminus}{ \myrvector{ \sqrttwo \\ -\sqrttwo } } $
# $ \newcommand{\myarray}[2]{ \begin{array}{#1}#2\end{array}} $
# $ \newcommand{\X}{ \mymatrix{cc}{0 & 1 \\ 1 & 0}  } $
# $ \newcommand{\Z}{ \mymatrix{rr}{1 & 0 \\ 0 & -1}  } $
# $ \newcommand{\Htwo}{ \mymatrix{rrrr}{ \frac{1}{2} & \frac{1}{2} & \frac{1}{2} & \frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & \frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} & \frac{1}{2} } } $
# $ \newcommand{\CNOT}{ \mymatrix{cccc}{1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0} } $
# $ \newcommand{\norm}[1]{ \left\lVert #1 \right\rVert } $
# $ \newcommand{\pstate}[1]{ \lceil \mspace{-1mu} #1 \mspace{-1.5mu} \rfloor } $

# <h2> Python: Quick Reference </h2>
# <hr>
# <ul>
#     <li><a href="#Variables">Variables</a></li>
#     <li><a href="#Arithmetic_operators">Arithmetic operators</a></li>
#     <li><a href="#Objects">Objects</a></li>
#     <li><a href="#Size_of_an_object">Size of an object</a></li>    
#     <li><a href="#Loops">Loops</a></li>
#     <li><a href="#Conditionals">Conditionals</a></li>
#     <li><a href="#Logical_and_Boolean_operators">Logical and Boolean operators</a></li>
#     <li><a href="#Double_list">Double list</a></li>
#     <li><a href="#List_operations">List operations</a></li>
#     <li><a href="#Functions">Functions</a></li>
#     <li><a href="#Random_number">Random number</a></li>
# </ul>
# <hr>

# <a id="Variables"></a>
# <h3> Variables </h3>

# +
number = 5 # integer
real = -3.4 # float

name = 'Asja' # string
surname = "Sarkana" # string

boolean1 = True # Boolean 
boolean2 = False # Boolean 
# -

# <hr>

# <a id="Arithmetic_operators"></a>
# <h3> Arithmetic operators </h3>

# <h4> Basic operators </h4>

# +
a = 13
b = 5
print("a =",a)
print("b =",b)
print()

# basics operators
print("a + b =",a+b)
print("a - b =",a-b)
print("a * b =",a*b)
print("a / b =",a/b)
# -

# <h4> Integer division and modulus operators </h4>

# +
a = 13
b = 5
print("a =",a)
print("b =",b)
print()

print("integer division:")
print("a//b =",a//b)

print("modulus operator:")
print("a mod b =",a % b)
# -

# <h4> Exponent operator</h4>
#
# number\*\*exponent

# +
b = 5
print("b =",b)
print()

print("b*b =",b**2)
print("b*b*b =",b**3)
print("sqrt(b)=",b**0.5)
# -

# <hr>

# <a id="Objects"></a>
# <h3> Objects </h3>

# <h4> Lists </h4>

# +
# list
mylist = [10,8,6,4,2] 

print(mylist)
# -

# <h4> Tuple </h4>

# +
# tuple
mytuple=(1,4,5,'Asja') 

print(mytuple)
# -

# <h4> Dictionary </h4>

# +
# dictionary
mydictionary = {
    'name' : "Asja",
    'surname':'Sarkane',
    'age': 23
}

print(mydictionary)

print(mydictionary['surname'])
# -

# <h4>List of the other objects or variables </h4>

# +
# list of the other objects or variables
list_of_other_objects =[
    mylist,
    mytuple,
    3,
    "Asja",
    mydictionary
]

print(list_of_other_objects)
# -

# <hr>

# <a id="Size_of_an_object"></a>
# <h3> Size of an object </h3>
#
# We use the method "len()" that takes an object as the input.

# +
# length of a string
print(len("<NAME>"))

# size of a list
print(len([1,2,3,4]))

# size of a dictionary
mydictionary = { 'name' : "Asja", 'surname':'Sarkane', 'age': 23}
print(len(mydictionary))
# -

# <hr>

# <a id="Loops"></a>
# <h3> Loops </h3>

# <h4> While-loop </h4>

i = 10
while i>0: # while condition(s):
    print(i)
    i = i - 1   

# <h4> For-loop </h4>

for i in range(10): # i is in [0,1,...,9]
    print(i)

for i in range(-5,6): # i is in [-5,-4,...,0,...,4,5]
    print(i)

for i in range(0,23,4): # i is in [0,4,8,12,16,20]
    print(i)

for i in [3,8,-5,11]: 
    print(i)

for i in "Sarkane":
    print(i)

# +
# dictionary
mydictionary = {
    'name' : "Asja",
    'surname':'Sarkane',
    'age': 23,
}

for key in mydictionary:
    print("key is",key,"and its value is",mydictionary[key])
# -

# <hr>

# <a id="Conditionals"></a>
# <h3>Conditionals </h3>

for a in range(4,7):
    
    # if condition(s)
    if a<5: 
        print(a,"is less than 5")
        
    # elif conditions(s)
    elif a==5: 
        print(a,"is equal to 5")
        
    # else
    else:
        print(a,"is greater than 5")

# <hr>

# <a id="Logical_and_Boolean_operators"></a>
# <h3>Logical and Boolean operators</h3>

# <h4> Logical operator "and"</h4>

# Logical operator "and"
i = -3
j = 4
if i<0 and j > 0:  
    print(i,"is negative AND",j,"is positive")

# <h4>Logical operator "or"</h4>

# Logical operator "or"
i = -2
j = 2
if i==2 or j == 2:  
    print("i OR j is 2: (",i,",",j,")")

# <h4>Logical operator "not" </h4>

# Logical operator "not"
i = 3
if not (i==2):
    print(i,"is NOT equal to 2")

# <h4> Operator "equal to" </h4>

# Operator "equal to"
i = -1
if i == -1:
    print(i,"is EQUAL TO -1")

# <h4> Operator "not equal to" </h4>

# Operator "not equal to"
i = 4
if i != 3:
    print(i,"is NOT EQUAL TO 3")

# <h4> Operator "less than or equal to" </h4>

# Operator "not equal to"
i = 2
if i <= 5:
    print(i,"is LESS THAN OR EQUAL TO 5")

# <h4> Operator "greater than or equal to" </h4>

# Operator "not equal to"
i = 5
if i >= 1:
    print(i,"is GREATER THAN OR EQUAL TO 3")

# <hr>

# <a id="Double_list"></a>
# <h3> Double list </h3>

# +
A =[
    [1,2,3],
    [-2,-4,-6],
    [3,6,9]
]

# print all
print(A)
print()

# print each list in a new line
for list in A:
    print(list)
# -

# <hr>

# <a id="List_operations"></a>
# <h3>List operations</h3>

# <h4> Concatenation of two lists </h4>

# +
list1 = [1,2,3]
list2 = [4,5,6]

#concatenation of two lists

list3 = list1 + list2
print(list3)

list4 = list2 + list1
print(list4)
# -

# <h4> Appending a new element </h4>

# +
list = [0,1,2]

list.append(3)
print(list)

list = list + [4]
print(list)


# -

# <hr>

# <a id="Functions"></a>
# <h3>Functions</h3>

# +
def summation_of_integers(n):
    summation = 0
    for integer in range(n+1):
        summation = summation + integer
    return summation

print(summation_of_integers(10))
print(summation_of_integers(20))
# -

# <hr>

# <a id="Random_number"></a>
# <h3>Random number</h3>
#
# We can use method "randrange()".

# +
from random import randrange

print(randrange(10),"is picked randomly between 0 and 9")
      
print(randrange(-9,10),"is picked randomly between -9 and 9")

print(randrange(0,20,3),"is picked randomly from the list [0,3,6,9,12,15,18]")
# -



StarcoderdataJupyterScriptsDedupFiltered