Skip to content

Commit 3749615

Browse files
Practice #4
1 parent d6a4db5 commit 3749615

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

practice_4.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
def analyze_numbers_and_print_FizzBuzz():
2+
for i in range(0, 101):
3+
if i % 3 == 0:
4+
print("Fizz")
5+
if i % 5 == 0:
6+
print("Buzz")
7+
if i % 15 == 0:
8+
print(i)
9+
print("FizzBuzz")
10+
11+
12+
analyze_numbers_and_print_FizzBuzz()
13+
14+
15+
def read_number_and_print_digit_by_digit(number):
16+
if len(number) != 5:
17+
print("The number must includes 5 digits! Please, try again!")
18+
return
19+
for index, item in enumerate(number):
20+
print("{} цифра равна {}".format(index+1, item))
21+
print("And from the end to the beginning!")
22+
for index, item in enumerate(number[::-1]):
23+
print("{} цифра равна {}".format(index+1, item))
24+
25+
26+
read_number_and_print_digit_by_digit("12345")
27+
read_number_and_print_digit_by_digit("123")
28+
29+
30+
def sorting_by_choice(array):
31+
for i in range(len(array)):
32+
for j in range(0, len(array) - i - 1):
33+
if array[j] > array[j + 1]:
34+
array[j], array[j+1] = array[j+1], array[j]
35+
print(array)
36+
37+
38+
array1 = [100, 2222222, 85, 789, 1, 1258, 1478952, 15, 58, 1, 65, 69, 78, 52, 2563, 1, 0, 3, 24, 2, 3, 7]
39+
sorting_by_choice(array1)
40+
41+
42+
def change_tab_for_whitespace(file_name, to_spaces=True):
43+
tab = "\t"
44+
whitespaces = " "
45+
with open(file_name, "r+") as file_for_read:
46+
buffer = file_for_read.read()
47+
if to_spaces:
48+
buffer = buffer.replace(tab, whitespaces)
49+
else:
50+
buffer = buffer.replace(whitespaces, tab)
51+
with open("file1.txt", "wt") as file_for_rewrite:
52+
file_for_rewrite.write(buffer)
53+
54+
55+
change_tab_for_whitespace("forRead.txt", to_spaces=True)
56+
57+
58+
def replace_with_a_template(str, dictionary):
59+
list = str.split(" ")
60+
for word in list:
61+
if word in dictionary:
62+
str = str.replace(word, dictionary[word])
63+
return str
64+
65+
66+
string123 = "Py is one of OOP language. There are 3 principles of OOP wich includes E and I and P."
67+
dictionary1 = {'OOP': 'object oriented programming', 'Py': 'Python', 'E': 'Encapsulation',
68+
'I': 'Inheritance', 'P.': 'Polymorphism.'}
69+
print(replace_with_a_template(string123, dictionary1))

0 commit comments

Comments
 (0)