Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
5-6
  • Loading branch information
AnnaAgf committed Oct 16, 2019
commit ea1f21dc681d422c0c5d203253145d69dc53b1e6
6 changes: 3 additions & 3 deletions lesson03/examples/3+_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

DIR = 'files'

wanted_symbol = "@"
# wanted_symbol = "+" # раскомментируйте, чтобы посмотреть как работает, если не найдено то, что искали
wanted_token = "@"
# wanted_token = "+" # раскомментируйте, чтобы посмотреть как работает, если не найдено то, что искали
with open(os.path.join(DIR, 'data'), 'r', encoding='UTF-8') as f:
for line in f: # считываем файл построчно
if wanted_symbol in line: # пока не найдем нужную информацию
if wanted_token in line: # пока не найдем нужную информацию
print(line)
break # как нашли, заканчиваем чтение файла
else:
Expand Down
2 changes: 1 addition & 1 deletion lesson03/examples/files/data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Hello world
Second string...
Secret symbol is "@"
Secret token is "@"
Привет мир!!!
18 changes: 18 additions & 0 deletions lesson03/home_work/hw03-5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,22 @@
Если специальный символ введен после нескольких чисел,
то вначале нужно добавить сумму этих чисел к полученной ранее сумме и после этого завершить программу.
'''
import sys

result = 0
while True:
line = input("Enter number or special token q fo exite: ")
tokens = line.split(" ")
for token in tokens:
try:
number = float(token)
result += number
except:
if token == 'q':
print(f"You sum is {result}. Program is terminated")
exit(0)
else:
print(f"You sum is {result}. Input error", file=sys.stderr)
exit(1)
#print(result)
#exit()
18 changes: 16 additions & 2 deletions lesson03/home_work/hw03-6.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,19 @@
Необходимо использовать написанную ранее функцию int_func().
'''

def int_func(a):

''' 1 Вариант
def func(a):
return a.title()
print(func("abca dsd"))'''

# 2 Вариант
def my_func(a):
separate_word = a.split(' ')
total = []
for i in separate_word:
string_element = str(i)
first_letter = string_element[:1].upper()
word = first_letter + string_element[1:]
total.append(word)
return total
print(my_func("hello world"))