├── For-Beginners
├── Lesson-10-if-elif-else.py
├── Lesson-11-Dictionary.py
├── Lesson-12-Dictionary.py
├── Lesson-13-Input.py
├── Lesson-14-Functions1.py
├── Lesson-15-Functions2.py
├── Lesson-16-Module.py
├── Lesson-17-Class1.py
├── Lesson-18-Class2.py
├── Lesson-19-Files.py
├── Lesson-20-Exceptions.py
├── Lesson-21-JSON.py
├── Lesson-22-Arguments.py
├── Lesson-23-RegExpression1.py
├── Lesson-24-RegExpression2.py
├── Lesson-25-PyGame.py
├── Lesson-26-27-MoveImage.py
├── Lesson-28-SnowFall.py
├── Lesson-30-SQLServer.py
├── Lesson-33-Part1.py
├── Lesson-33-Part2.py
├── Lesson-33-Part3.py
├── Lesson-4-Variables.py
├── Lesson-5-Strings.py
├── Lesson-6-Numbers.py
├── Lesson-7-Loops.py
├── Lesson-8-Lists1.py
├── Lesson-9-Lists2.py
├── hero.py
├── mymodule.py
├── processorI7.png
├── snow1.png
├── snow2.png
├── snow3.png
└── snow4.png
└── For-NoBeginners
├── Lesson-1-Recursion.py
├── Lesson-2-BinarySearch.py
├── Lesson-3-BubbleSort.py
├── Lesson-4-PurgeLog.py
├── Lesson-5-CleanUp.py
└── Lesson-6-Flask
├── Flaskv2.zip
├── application.py
├── mypage.html
└── requirements.txt
/For-Beginners/Lesson-10-if-elif-else.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | age = 14
11 |
12 | if (age <= 4):
13 | print("You are baby!")
14 | elif (age > 4) and (age < 12):
15 | print("You age kid")
16 | elif (age >= 12) and (age < 19):
17 | print("You age teenager")
18 | else:
19 | print("You are old!")
20 |
21 | print("----END----")
22 |
23 |
24 | all_cars = ['chrusler', 'dacia', 'bmw', 'KIA', 'vw', 'seat', 'skoda', 'lada', 'audi', 'ford', 'Chevrolett']
25 | german_cars = ['bmw', 'vw', 'audi']
26 |
27 |
28 | for xxxx in all_cars:
29 | if xxxx not in german_cars:
30 | print(xxxx + " is not German Car" + " index = " + str(all_cars.index(xxxx)))
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-11-Dictionary.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 | # (-----Item------)
10 | # (key) (value)
11 | enemy = {
12 | 'loc_x': 70,
13 | 'loc_y': 50,
14 | 'color': 'green',
15 | 'health': 100,
16 | 'name': 'Mudillo',
17 | }
18 |
19 |
20 | print(enemy)
21 |
22 | print("Location X = " + str(enemy['loc_x']))
23 | print("Location Y = " + str(enemy['loc_y']))
24 | print("His name is: " + enemy['name'])
25 |
26 | enemy['rank'] = 'Admiral'
27 | print(enemy)
28 |
29 | del enemy['rank']
30 | print(enemy)
31 |
32 |
33 | enemy['loc_x'] = enemy['loc_x'] + 40
34 | enemy['health'] = enemy['health'] - 30
35 | if enemy['health'] < 80:
36 | enemy['color'] = 'yellow'
37 |
38 | print(enemy)
39 |
40 |
41 | print(enemy.keys())
42 | print(enemy.values())
43 |
44 |
45 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-12-Dictionary.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | enemy = {
11 | 'loc_x': 70,
12 | 'loc_y': 50,
13 | 'color': 'green',
14 | 'health': 100,
15 | 'name': 'Mudillo',
16 | 'image': ['image1.jpg', 'image2.jpg', 'image3.jpg']
17 | }
18 |
19 | all_enemies = []
20 |
21 | for x in range(0, 10):
22 | all_enemies.append(enemy.copy())
23 |
24 |
25 | for ene in all_enemies:
26 | print(ene)
27 |
28 | all_enemies[5]['health'] = 30
29 | all_enemies[8]['name'] = "Kozel"
30 | all_enemies[2]['loc_x'] += 10
31 |
32 |
33 | print("-----------------------")
34 | for ene in all_enemies:
35 | print(ene)
--------------------------------------------------------------------------------
/For-Beginners/Lesson-13-Input.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | mylist = []
11 | msg =""
12 |
13 | while msg != 'stop'.upper():
14 | msg = input("Enter new item, and STOP to finish ")
15 | mylist.append(msg)
16 |
17 | print(mylist)
18 |
19 |
20 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-14-Functions1.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | def napeshatat_privetstvie(name):
12 | """Print Privetstrvie"""
13 | print("Congratulations " + name + " wish you all the best!")
14 |
15 |
16 | def summa(x, y):
17 | return x+y
18 |
19 |
20 | def factorial(x):
21 | """Calculate Factorial of number X"""
22 | otvet = 1
23 | for i in range(1, x + 1):
24 | otvet = otvet * i
25 | return otvet
26 |
27 |
28 |
29 | print("---------------------------------")
30 | napeshatat_privetstvie("Denis")
31 | napeshatat_privetstvie("Vasya")
32 |
33 | x = summa(33, 22)
34 | print(x)
35 |
36 |
37 | for i in range(1, 10):
38 | print(str(i) + "!\t = " + str(factorial(i)))
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-15-Functions2.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | def create_record(name, telephone, address):
12 | """Create Record"""
13 | record = {
14 | 'name': name,
15 | 'phone': telephone,
16 | 'address': address
17 | }
18 | return record
19 |
20 |
21 | user1 = create_record("Vasya", "+97123123123123123","Tinussiya")
22 | user2 = create_record("Petay", "+64646464646466466","Munisiya")
23 |
24 | print(user1)
25 | print(user2)
26 |
27 |
28 | def give_award(medal, *persons):
29 | """Give Medals to persons"""
30 | for person in persons:
31 | print("Tovarish " + person.title() + " nagrajdaetsya medaliyu " + medal)
32 |
33 |
34 | give_award("Za Berlin", "vasya", "petya")
35 | give_award("Za London", "petya", "alexander","valintin")
36 |
37 |
38 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-16-Module.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 | from mymodule import *
10 |
11 | # -----# ------------------MAIN------------------------
12 | bbb()
13 | ccc()
14 | aaa()
15 |
16 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-17-Class1.py:
--------------------------------------------------------------------------------
1 | from hero import *
2 | # ---------------MAIN ------------------------------------
3 |
4 | myhero1 = Hero("Vurdalak", 5, "Orc")
5 | myhero2 = Hero("Alexander", 4, "Human")
6 |
7 | myhero1.show_hero()
8 | myhero2.move()
9 | myhero1.level_up()
10 | myhero1.show_hero()
11 | myhero1.set_health(60)
12 | myhero1.show_hero()
13 |
14 |
15 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-18-Class2.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | from hero import *
12 |
13 |
14 | myhero = Hero("Vurdalak", 4, "Orc")
15 | mysuperhero = SuperHero("Moisey", 10, "Human", 5)
16 |
17 | myhero.show_hero()
18 | mysuperhero.show_hero()
19 |
20 | mysuperhero.makemagic()
21 | mysuperhero.show_hero()
22 |
23 | mysuperhero.makemagic()
24 | mysuperhero.makemagic()
25 | mysuperhero.show_hero()
26 |
27 |
28 | mysuperhero.magic = 10
29 | mysuperhero.show_hero()
30 |
31 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-19-Files.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | inputfile = "../list_of_password.txt"
12 | outputfile = "../my_passwords.txt"
13 |
14 | password_tolookfor = "kolya"
15 |
16 | myfile1 = open(inputfile, mode='r', encoding='latin_1')
17 | myfile2 = open(outputfile, mode='a', encoding='latin_1')
18 |
19 | for num, line in enumerate(myfile1, 1):
20 | if password_tolookfor in line:
21 | print("Line N: " + str(num) + " : " + line.strip())
22 | myfile2.write("Found password:" + line)
23 |
24 |
25 | myfile1.close()
26 | myfile2.close()
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-20-Exceptions.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 | import sys
10 |
11 | filename = "Lesson_List.txt"
12 |
13 | while True:
14 | try:
15 | print("Inside TRY")
16 | myfile = open(filename, mode='r', encoding="Latin-1")
17 | except Exception:
18 | print("Inside EXCEPT")
19 | print("Error Found!")
20 | print(sys.exc_info()[1])
21 | filename = input("ENter Correct file name! :")
22 | else:
23 | print("Indise ELSE")
24 | print(myfile.read())
25 | break
26 |
27 |
28 | print("======================EOF================")
29 |
30 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-21-JSON.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 | import json
10 | filename = "user_settings.txt"
11 | myfile = open(filename, mode='w', encoding='Latin-1')
12 |
13 | player1 = {
14 | 'PlayerName': "Donald Trump",
15 | 'Score': 345,
16 | 'awards': ["OR", "NV", "NY"]
17 | }
18 |
19 | player2 = {
20 | 'PlayerName': "Clinton Hillary",
21 | 'Score': 346,
22 | 'awards': ["WT", "TX", "MI"]
23 | }
24 |
25 | myplayers = []
26 | myplayers.append(player1)
27 | myplayers.append(player2)
28 |
29 | # ------------ SAVE by JSON -----------
30 |
31 | json.dump(myplayers, myfile)
32 | myfile.close()
33 |
34 |
35 | # -------- LAOD by JSON --------
36 |
37 | myfile = open(filename, mode='r', encoding='Latin-1')
38 | json_data = json.load(myfile)
39 |
40 | for user in json_data:
41 | print("Player Name is: " + str(user['PlayerName']))
42 | print("Player Score is: " + str(user['Score']))
43 | print("Player Award N1: " + str(user['awards'][0]))
44 | print("Player Award N2: " + str(user['awards'][1]))
45 | print("Player Award N3: " + str(user['awards'][2]))
46 | print("----------------------------------\n\n")
47 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-22-Arguments.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 | import sys
10 | import os
11 |
12 | x = len(sys.argv)
13 |
14 | if x > 1:
15 | if sys.argv[1] == "/?":
16 | print("Help Requested")
17 | print("Usage of this program is: python.exe myfile.py argv1 argv2")
18 | print("Arguments entered: " + str(sys.argv[1:]))
19 | else:
20 | print("Argumets NOT PROVIDED")
21 |
22 | os.system("dir > test.txt")
23 | sys.exit()
24 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-23-RegExpression1.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | import re
11 |
12 | mytext = "Vasya aaaaaaaa 1972, Kolya - 19727777: Olesya 1981, aaaaaa@intel.com," \
13 | "bbbbbbbbbb@intel.com, Petya ggggggggg, 1992,cccccccccc@yahoo.com, " \
14 | "ddddddddddd@intel.com, vasya@yandex.net, hello hello, Misha #43 1984, " \
15 | "Vladimir 1977, Irina , 2001, annnnnnn@intel.com, eeeeeeee@yandex.com," \
16 | "ooooooooooo@hotmai.gov, gggggggggggg@gov.gov, tututut@giv.hot"
17 |
18 | """
19 | \d = Any Digit 0-9
20 | \D = Any non DIGIT
21 | \w = Any Alphabet symbol [A-Z a-z]
22 | \W = Any non Alphabet symbol
23 | \s = breakspace
24 | \S = non breakspace
25 | [0-9]{3}
26 | [A-Z][a-z]+
27 |
28 | """
29 |
30 | textlookfor = r"@\w+\.\w+"
31 | allresults = re.findall(textlookfor, mytext)
32 |
33 | print(allresults)
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-24-RegExpression2.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 | import re
10 |
11 | input_filename = "../dumpfile.txt"
12 | reult_filename = "../results.txt"
13 |
14 | inputfile = open(input_filename, mode='r', encoding='Latin-1')
15 | resulfile = open(reult_filename, mode='w', encoding='Latin-1')
16 | mytext = inputfile.read()
17 |
18 | lookfor = r"[\w._-]+@(?!intel\.com)[\w._-]+\.[\w.]+"
19 |
20 | results = re.findall(lookfor, mytext)
21 |
22 | for item in results:
23 | print(item)
24 | resulfile.write(item + "\n")
25 |
26 |
27 | print("Total: " + str(len(results)))
28 |
29 | inputfile.close()
30 | resulfile.close()
31 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-25-PyGame.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | import pygame
11 |
12 | pygame.init()
13 | screen = pygame.display.set_mode((800, 600))
14 |
15 |
16 | while True:
17 | pygame.display.flip()
18 |
19 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-26-27-MoveImage.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | import pygame
11 |
12 | MAX_X = 1920
13 | MAX_Y = 1080
14 | IMG_SIZE = 100
15 |
16 | game_over = False
17 | bg_color = (0, 10, 0)
18 |
19 | pygame.init()
20 | screen = pygame.display.set_mode((MAX_X, MAX_Y), pygame.FULLSCREEN)
21 | pygame.display.set_caption("My First PyGame Game! :)")
22 |
23 | myimage = pygame.image.load("processorI7.png").convert()
24 | myimage = pygame.transform.scale(myimage, (IMG_SIZE, IMG_SIZE))
25 |
26 | x = 500
27 | y = 100
28 |
29 | move_right = False
30 | move_left = False
31 | move_up = False
32 | move_down = False
33 |
34 | # -------------MAIN GAME LOOP ----------------------------
35 | while game_over == False:
36 | for event in pygame.event.get():
37 | if event.type == pygame.KEYDOWN:
38 | if event.key == pygame.K_ESCAPE:
39 | game_over = True
40 | if event.key == pygame.K_LEFT:
41 | move_left = True
42 | if event.key == pygame.K_RIGHT:
43 | move_right = True
44 | if event.key == pygame.K_UP:
45 | move_up = True
46 | if event.key == pygame.K_DOWN:
47 | move_down = True
48 |
49 | if event.type == pygame.KEYUP:
50 | if event.key == pygame.K_LEFT:
51 | move_left = False
52 | if event.key == pygame.K_RIGHT:
53 | move_right = False
54 | if event.key == pygame.K_UP:
55 | move_up = False
56 | if event.key == pygame.K_DOWN:
57 | move_down = False
58 | if event.type == pygame.MOUSEBUTTONDOWN:
59 | x, y = event.pos
60 |
61 | if move_left == True:
62 | x -= 1
63 | if x < 0:
64 | x = 0
65 | if move_right == True:
66 | x += 1
67 | if x > MAX_X - IMG_SIZE:
68 | x = MAX_X - IMG_SIZE
69 | if move_up == True:
70 | y -= 1
71 | if y < 0:
72 | y = 0
73 | if move_down == True:
74 | y += 1
75 | if y > MAX_Y - IMG_SIZE:
76 | y = MAX_Y - IMG_SIZE
77 |
78 | screen.fill(bg_color)
79 | screen.blit(myimage, (x, y))
80 | pygame.display.flip()
81 |
82 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-28-SnowFall.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | import pygame
11 | import random
12 | import sys
13 | import time
14 |
15 | MAX_X = 1366
16 | MAX_Y = 768
17 | MAX_SNOW = 100
18 | SNOW_SIZE = 64
19 |
20 | class Snow():
21 | def __init__(self, x, y):
22 | self.x = x
23 | self.y = y
24 | self.speed = random.randint(1, 3)
25 | self.img_num = random.randint(1, 4)
26 | self.image_filename = "snow" + str(self.img_num) + ".png"
27 | self.image = pygame.image.load(self.image_filename).convert_alpha()
28 | self.image = pygame.transform.scale(self.image, (SNOW_SIZE, SNOW_SIZE))
29 |
30 | def move_snow(self):
31 | self.y = self.y + self.speed
32 | if self.y > MAX_Y:
33 | self.y = (0 - SNOW_SIZE)
34 |
35 | i = random.randint(1, 3)
36 | if i == 1: # Move RIGHT
37 | self.x += 1
38 | if self.x > MAX_X:
39 | self.x = (0 - SNOW_SIZE)
40 | elif i == 2: # Move LEFT
41 | self.x -= 1
42 | if self.x < (0 - SNOW_SIZE):
43 | self.x = MAX_X
44 |
45 | def draw_snow(self):
46 | screen.blit(self.image, (self.x, self.y))
47 |
48 |
49 | def initilize_snow(max_snow, snowfall):
50 | for i in range(0, max_snow):
51 | xx = random.randint(0, MAX_X)
52 | yy = random.randint(0, MAX_Y)
53 | snowfall.append(Snow(xx, yy))
54 |
55 | def check_for_exit():
56 | for event in pygame.event.get():
57 | if event.type == pygame.KEYDOWN:
58 | sys.exit()
59 |
60 | # ------------------------- MAIN ----------------------
61 |
62 | pygame.init()
63 |
64 | screen = pygame.display.set_mode((MAX_X, MAX_Y), pygame.FULLSCREEN)
65 |
66 | bg_color = (0 ,0 ,0)
67 | snowfall = []
68 |
69 | initilize_snow(MAX_SNOW, snowfall)
70 |
71 | while True:
72 | screen.fill(bg_color)
73 | check_for_exit()
74 | for i in snowfall:
75 | i.move_snow()
76 | i.draw_snow()
77 | time.sleep(0.0020)
78 | pygame.display.flip()
79 |
80 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-30-SQLServer.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | import pypyodbc
11 |
12 | mySQLServer = "MANOWAR\SQLEXPRESS"
13 | myDatabase = "northwind"
14 |
15 | connection = pypyodbc.connect('Driver={SQL Server};'
16 | 'Server=' + mySQLServer + ';'
17 | 'Database=' + myDatabase + ';')
18 |
19 | cursor = connection.cursor()
20 |
21 | mySQLQuery = ("""
22 | SELECT CompanyName, ContactName, country
23 | FROM dbo.Customers
24 | WHERE country = 'Canada'
25 | """)
26 |
27 | cursor.execute(mySQLQuery)
28 | results = cursor.fetchall()
29 |
30 | for row in results:
31 | companyname = row[0]
32 | contactname = row[1]
33 | contryname = row[2]
34 |
35 | print("Welcome :" + str(companyname) + " User: " + str(contactname) + " From: " + str(contryname))
36 |
37 | connection.close()
38 |
39 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-33-Part1.py:
--------------------------------------------------------------------------------
1 | from urllib import request
2 |
3 | myUrl = "http://www.astahov.net"
4 |
5 | otvet = request.urlopen(myUrl)
6 | mytext1 = otvet.readlines()
7 | #mytext2 = otvet.read()
8 | #print(otvet)
9 |
10 | #print(mytext2)
11 |
12 | for line in mytext1:
13 | print(str(line).lstrip("b'").rstrip("\\r\\n'"))
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-33-Part2.py:
--------------------------------------------------------------------------------
1 | from urllib import request, parse
2 | import sys
3 |
4 | myUrl = "http://www.google.com/search?"
5 | value = {'q': 'ANDESA Soft'}
6 |
7 | myheader = {}
8 | myheader['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
9 |
10 | try:
11 | mydata = parse.urlencode(value)
12 | print(mydata)
13 | myUrl = myUrl + mydata
14 | req = request.Request(myUrl, headers=myheader)
15 | otvet = request.urlopen(req)
16 | otvet = otvet.readlines()
17 | for line in otvet:
18 | print(line)
19 | except Exception:
20 | print("Error occuried during web request!!")
21 | print(sys.exc_info()[1])
22 |
23 |
24 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-33-Part3.py:
--------------------------------------------------------------------------------
1 | from urllib import request
2 | import sys
3 |
4 |
5 | myUrl = "http://adv400.tripod.com/kartinka.jpg"
6 | myFile = "G:\\MyPython\\MyDownloads\\mykartinka.jpg"
7 |
8 | try:
9 | print("Start Downloading file from: " + myUrl)
10 | request.urlretrieve(myUrl, myFile)
11 | except Exception:
12 | print("AHTUNG!!!")
13 | print(sys.exc_info())
14 | exit
15 |
16 | print("File Downloaded and saved at:" + myFile)
17 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-4-Variables.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | #
8 | # ------------------------------------------------
9 |
10 |
11 |
12 | a = "Hello"
13 | b = 25
14 | c = 2342365462536253562
15 |
16 | d = "Morning!"
17 |
18 | print(a + " " + d)
19 | print("My Age is: " + str(b))
20 |
21 | num1 = 1111111111111111111
22 | num2 = 3333333333333333333
23 | print(num1 + num2)
24 |
25 | num3 = num2*num1
26 | print(num3)
27 |
28 | l_name = "stevenson"
29 | f_name = "david"
30 |
31 | print(l_name + " " + f_name)
32 |
33 | vvv = "434"
34 | VVV = "678"
35 |
36 | print(vvv + "-" + VVV)
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-5-Strings.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | #
8 | # ------------------------------------------------
9 |
10 |
11 | mystring = "Bla bla bla"
12 |
13 | name = "mr vASya pupkin"
14 |
15 | print(name.title())
16 | print(name.upper())
17 | print(name.lower())
18 |
19 | print("Privet stroka nomer1\nPrivet stroka N2\n\nStroka N3")
20 | print("Messages:\n\tMessage1\n\tMessage2\n\tMessage3\nEND")
21 | print("Lower name: " + name.lower())
22 | print("--------------------------\n\n")
23 | a = "..... dadya vasya ...."
24 | print(a)
25 | print(a.rstrip())
26 | print(a.lstrip())
27 | print(a.strip())
28 |
29 | a = "..... dadya vasya ...."
30 | a = a.strip(".") # Udalenie to4ek
31 | a = a.strip() # Udalenie probelov
32 | print(a.title())
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-6-Numbers.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | num1 = 30
12 | num2 = 45
13 | num3 = num1 + 10
14 | print(num1 + num2)
15 | print(num3)
16 |
17 | x1 = 333333333333333333333333333333333333333333333333333333333333
18 | x2 = 777777777777777777777777777777777777777777777777777777777777
19 |
20 | print(x1 +x2)
21 | print(x1*x2 + 10)
22 | print(num2/3)
23 |
24 |
25 |
26 | x1 = 6
27 | x2 = 4
28 | print(x1 / x2)
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-7-Loops.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | for x in range(100, 10, -2):
12 | print("Number x = " + str(x))
13 |
14 | print("------------EOF-------------------")
15 |
16 | x =0
17 |
18 | while True:
19 | print(x)
20 | x = x + 1
21 | if x == 100:
22 | break
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-8-Lists1.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | cities = ['New York', 'Moscow', 'new dehli', 'Simferopol', 'Toronto']
12 |
13 | print(cities)
14 | print(len(cities))
15 |
16 | print(cities[0])
17 | print(cities[-2])
18 | print(cities[2].upper())
19 |
20 | cities[2] = 'Tula'
21 | print(cities)
22 |
23 | cities.append('Kursk')
24 | cities.append('Yalta')
25 | print(cities)
26 |
27 | cities.insert(2, 'Feodosiya')
28 | print(cities)
29 |
30 |
31 | del cities[-1]
32 | print(cities)
33 |
34 | cities.remove('Tula')
35 | print(cities)
36 |
37 | deleted_city = cities.pop()
38 | print("Deleted city is: " + deleted_city)
39 | print(cities)
40 |
41 |
42 | cities.reverse()
43 | print(cities)
44 |
45 |
46 |
47 | cities = ['New York', 'Moscow', 'new dehli', 'Simferopol', 'Toronto']
48 |
49 | print(cities[-4:-2])
50 |
--------------------------------------------------------------------------------
/For-Beginners/Lesson-9-Lists2.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | # 0 1 2 3 4
11 | cars = ['bmw', 'vw', 'seat', 'skoda', 'kada']
12 |
13 | for x in cars:
14 | print(x.upper())
15 |
16 |
17 | for x in range(1, 6):
18 | print(x)
19 |
20 | mynumber_list = list(range(0, 10))
21 | print(mynumber_list)
22 | print("===============================================")
23 |
24 | for x in mynumber_list:
25 | x = x * 2
26 | print(x)
27 |
28 | mynumber_list.sort(reverse=True)
29 | print(mynumber_list)
30 |
31 | print("Max number is: " + str(max(mynumber_list)))
32 | print("Min number is: " + str(min(mynumber_list)))
33 | print("Sum of list is: " + str(sum(mynumber_list)))
34 |
35 | print("===============================================")
36 |
37 | # 0 1 2 3 4
38 | cars = ['bmw', 'vw', 'seat', 'skoda', 'kada']
39 |
40 | mycars = cars[1:4]
41 | print(mycars)
42 | mycars = cars[:4]
43 | print(mycars)
44 |
45 | mycars = cars[-3:-1]
46 | print(mycars)
47 |
48 |
49 | # 0 1 2 3 4
50 | cars = ['bmw', 'vw', 'seat', 'skoda', 'kada']
51 | mycars = cars
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/For-Beginners/hero.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 | class Hero():
11 | """ Class to Create Hero for our Game"""
12 | def __init__(self, name, level, race):
13 | """Initiate our hero"""
14 | self.name = name
15 | self.level = level
16 | self.race = race
17 | self.health = 100
18 |
19 | def show_hero(self):
20 | """ Print all parameters of this Hero"""
21 | discription = (self.name + " Level is: " + str(self.level) + " Race is: " + self.race + " Health is " + str(self.health)).title()
22 | print(discription)
23 |
24 | def level_up(self):
25 | """ Upgrade Level of Hero"""
26 | self.level += 1
27 |
28 | def move(self):
29 | """ Start moving hero"""
30 | print("Hero " + self.name + " start moving...")
31 |
32 | def set_health(self, new_health):
33 | self.health = new_health
34 |
35 | # ---------------------------------------------------------------------
36 |
37 |
38 | class SuperHero(Hero):
39 | """ Class to Crete SUper Hero"""
40 | def __init__(self, name, level, race, magiclevel):
41 | """Initiate our Super Hero"""
42 | super().__init__(name, level, race)
43 | self.magiclevel = magiclevel
44 | self.magic = 100
45 |
46 | def makemagic(self):
47 | """ Use magic"""
48 | self.magic -= 10
49 |
50 | def show_hero(self):
51 | discription = (self.name + " Level is: " + str(self.level) + " Race is: " + self.race + " Health is " + str(self.health) +
52 | " Magic is: " + str(self.magic)).title()
53 | print(discription)
54 |
55 |
--------------------------------------------------------------------------------
/For-Beginners/mymodule.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2016 Initial Version
7 | # Hello Hello
8 | # ------------------------------------------------
9 |
10 |
11 | def aaa():
12 | print("AAAA")
13 |
14 |
15 | def bbb():
16 | print("BBBB")
17 |
18 |
19 | def ccc():
20 | print("CCCC")
21 |
22 |
23 | def ddd():
24 | print("DDDD")
25 |
--------------------------------------------------------------------------------
/For-Beginners/processorI7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adv4000/Python-Lessons/994dc9c3947ca131016aa91af018e359f6956ba0/For-Beginners/processorI7.png
--------------------------------------------------------------------------------
/For-Beginners/snow1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adv4000/Python-Lessons/994dc9c3947ca131016aa91af018e359f6956ba0/For-Beginners/snow1.png
--------------------------------------------------------------------------------
/For-Beginners/snow2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adv4000/Python-Lessons/994dc9c3947ca131016aa91af018e359f6956ba0/For-Beginners/snow2.png
--------------------------------------------------------------------------------
/For-Beginners/snow3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adv4000/Python-Lessons/994dc9c3947ca131016aa91af018e359f6956ba0/For-Beginners/snow3.png
--------------------------------------------------------------------------------
/For-Beginners/snow4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adv4000/Python-Lessons/994dc9c3947ca131016aa91af018e359f6956ba0/For-Beginners/snow4.png
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-1-Recursion.py:
--------------------------------------------------------------------------------
1 |
2 | """
3 | Recursion Functions
4 |
5 | 1) privet
6 | 2) privet n times
7 | 3) Sum 0+1+2+3+4+5
8 | 4) Factorial 5! = 1*2*3*4*5 = 120
9 | 5) Fibonacci 0,1,1,2,3,5,8,13,21,34,55,89
10 | """
11 | import sys
12 | sys.setrecursionlimit(3000)
13 |
14 |
15 | def privet(x):
16 | if x == 0:
17 | return
18 | print("Hello ", str(x))
19 | privet(x-1)
20 |
21 |
22 | def fibo(x):
23 | if x == 0:
24 | return 0
25 | elif x == 1:
26 | return 1
27 | else:
28 | return fibo(x-1) + fibo(x-2)
29 |
30 | #print(fido(50))
31 | privet(1999)
32 |
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-2-BinarySearch.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2017 Initial Version
7 | #
8 | # ------------------------------------------------
9 |
10 |
11 | def binarysearch(mylist, iskat, start, stop):
12 | if start > stop:
13 | return False
14 | else:
15 | mid = (start + stop) // 2
16 | if iskat == mylist[mid]:
17 | return mid
18 | elif iskat < mylist[mid]:
19 | return binarysearch(mylist, iskat, start, mid - 1)
20 | else:
21 | return binarysearch(mylist, iskat, mid + 1, stop)
22 |
23 |
24 | mylist = [10, 12, 13, 15, 20, 24, 27, 33, 42, 51, 57, 68, 70, 77, 79, 81]
25 | iskat = 10
26 | start = 0
27 | stop = len(mylist)
28 |
29 | x = binarysearch(mylist, iskat, start, stop)
30 |
31 | if x == False:
32 | print("Item ", iskat, "Not Found!")
33 | else:
34 | print("Item ", iskat, "Found at Index ", x)
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-3-BubbleSort.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 2017 Initial Version
7 | #
8 | # ------------------------------------------------
9 |
10 | oldlist = [10, 75, 43, 15, 25, -4, 27]
11 |
12 | def bubble_sort(mylist):
13 | last_item = len(mylist) - 1
14 | for z in range(0, last_item):
15 | for x in range(0, last_item-z):
16 | print(mylist)
17 | if mylist[x] > mylist[x+1]:
18 | mylist[x], mylist[x+1] = mylist[x+1], mylist[x]
19 |
20 | return mylist
21 |
22 | print("Old List: ", oldlist)
23 | newlist = bubble_sort(oldlist).copy()
24 | print("New List: ", newlist)
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-4-PurgeLog.py:
--------------------------------------------------------------------------------
1 | #!/bin/python3
2 | # ------------------------------------------------
3 | # Program by Denis.A.
4 | #
5 | #
6 | # Version Date Info
7 | # 1.0 2017 Initial Version
8 | #
9 | # ------------------------------------------------
10 |
11 | import shutil # For CopyFile
12 | import os # For GetFileSize and Check If File exist
13 | import sys # For CLI Arguments
14 |
15 | # lesson-4-putgelog.py mylog.txt 10 5
16 |
17 | if(len(sys.argv) < 4):
18 | print("Missing arguments! Usage is script.py mylog.txt 10 5")
19 | exit(1)
20 |
21 | file_name = sys.argv[1]
22 | limitsize = int(sys.argv[2])
23 | logsnumber = int(sys.argv[3])
24 |
25 | if(os.path.isfile(file_name) == True): # Check if MAIN logfile file exist
26 | logfile_size = os.stat(file_name).st_size # Get Filesize in BYTES
27 | logfile_size = logfile_size / 1024 # Convert from BYTES to KILOBYTES
28 |
29 | if(logfile_size >= limitsize):
30 | if(logsnumber > 0):
31 | for currentFileNum in range(logsnumber, 1, -1):
32 | src = file_name + "_" + str(currentFileNum-1)
33 | dst = file_name + "_" + str(currentFileNum)
34 | if(os.path.isfile(src) == True):
35 | shutil.copyfile(src, dst)
36 | print("Copied: " + src + " to " + dst)
37 |
38 | shutil.copyfile(file_name, file_name + "_1")
39 | print("Copied: " + file_name + " to " + file_name + "_1")
40 | myfile = open(file_name, 'w')
41 | myfile.close()
42 |
43 |
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-5-CleanUp.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis.A.
3 | # Version Date Info
4 | # 1.0 2017 Initial Version
5 | # ------------------------------------------------
6 | import os, time
7 |
8 | DAYS = 3 # Maximal age of file to stay, older will be deleted
9 | FOLDERS = [
10 | "G:\Musorka\HLAM",
11 | "G:\Musorka\MUSOR",
12 | "G:\Musorka\RAZNOE GAVNO"
13 | ]
14 | TOTAL_DELETED_SIZE = 0 # Total deleted size of all files in BYTES
15 | TOTAL_DELETED_FILE = 0 # Total deleted files
16 | TOTAL_DELETED_DIRS = 0 # Total deleted empty folders
17 |
18 | nowTime = time.time() # Get Current time in SECONDS
19 | ageTime = nowTime - 60*60*24*DAYS # Minus DAYS in SECONDS
20 |
21 | def delete_old_files(folder):
22 | """Delete files older than X DAYS"""
23 | global TOTAL_DELETED_FILE
24 | global TOTAL_DELETED_SIZE
25 | for path, dirs, files in os.walk(folder):
26 | for file in files:
27 | fileName = os.path.join(path, file) # get Full PATH to file
28 | fileTime = os.path.getmtime(fileName)
29 | if fileTime < ageTime:
30 | sizeFile = os.path.getsize(fileName)
31 | TOTAL_DELETED_SIZE += sizeFile # Count SUM of all free space
32 | TOTAL_DELETED_FILE += 1 # Count number of deleted files
33 | print("Deleting file: " + str(fileName))
34 | os.remove(fileName) # Delete file
35 |
36 | def delete_empty_dir(folder):
37 | global TOTAL_DELETED_DIRS
38 | empty_folders_in_this_run = 0
39 | for path, dirs, files in os.walk(folder):
40 | if (not dirs) and (not files):
41 | TOTAL_DELETED_DIRS += 1
42 | empty_folders_in_this_run += 1
43 | print("Deleting EMPTY Dir: " + str(path))
44 | os.rmdir(path)
45 | if empty_folders_in_this_run > 0:
46 | delete_empty_dir(folder)
47 |
48 | #=====================MAIN==============================
49 | starttime = time.asctime()
50 |
51 | for folder in FOLDERS:
52 | delete_old_files(folder) # Delete old files
53 | delete_empty_dir(folder) # Delete empty folders
54 |
55 | finishtime = time.asctime()
56 |
57 | print("-----------------------------------------------------")
58 | print("START TIME: " + str(starttime))
59 | print("Total Deleted Size : " + str(int(TOTAL_DELETED_SIZE/1024/1024)) + "MB")
60 | print("Total Deleted files: " + str(TOTAL_DELETED_FILE))
61 | print("Total Deleted Empty folders: " + str(TOTAL_DELETED_DIRS))
62 | print("FINISH TIME: " + str(finishtime))
63 | print("-------------------EOF-------------------------------")
64 |
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-6-Flask/Flaskv2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/adv4000/Python-Lessons/994dc9c3947ca131016aa91af018e359f6956ba0/For-NoBeginners/Lesson-6-Flask/Flaskv2.zip
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-6-Flask/application.py:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------
2 | # Program by Denis Astahov
3 | #
4 | #
5 | # Version Date Info
6 | # 1.0 23-Nov-2019 Initial Version
7 | #
8 | # ----------------------------------------------
9 |
10 | from flask import Flask
11 |
12 | application = Flask(__name__)
13 |
14 |
15 | @application.route("/")
16 | def index():
17 | return "Hello World from Flask Main Page"
18 |
19 | @application.route("/help")
20 | def helppage():
21 | return "This is Help Page v2!!!"
22 |
23 |
24 | @application.route("/user")
25 | def usermain_page():
26 | return "User's Main Page"
27 |
28 |
29 | @application.route("/user/")
30 | def show_user_page(username):
31 | return "Hello " + username.upper()
32 |
33 |
34 | @application.route("/path/")
35 | def print_subpath(subpath):
36 | return "SubPath is: " + subpath
37 |
38 |
39 | @application.route("/kvadrat/")
40 | def calc_kvadrat(x):
41 | return "Kvadrat ot: " + str(x) + " = " + str(x*x)
42 |
43 |
44 | @application.route("/htmlpage")
45 | def show_html_page():
46 | myfile = open("mypage.html", mode='r')
47 | page = myfile.read()
48 | myfile.close()
49 | return page
50 |
51 |
52 | #--------Main------------------
53 | if __name__ == "__main__":
54 | # application.debug = True
55 | # application.env = "Working Hard"
56 | application.run()
57 | #------------------------------
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-6-Flask/mypage.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ADV-IT
5 |
20 |
21 |
22 | Hello from Denis Astahov!
23 | Welcome to Python Flask Web Page!
24 | Python Flask = RULEZZzz!
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/For-NoBeginners/Lesson-6-Flask/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==1.1.1
2 |
--------------------------------------------------------------------------------