Untitled
unknown
plain_text
3 years ago
2.4 kB
5
Indexable
f1 = open("file_1.txt", "w")
while True:
temp = input()
f1.write(temp + "\n")
if len(temp) == 0:
break
f1.close()
f1 = open("file_1.txt")
f2 = open("file_2.txt", "w")
for line in f1:
count = 0
if len(line.split()) == 1:
f2.write(line)
f1.close()
f2.close()
-----------------------------------------------------------------------------------------------------------
check = True
while check:
print("1 - destination, 2 - price < 50, 0 - exit")
try:
my_file = open("file_3.txt")
choice = int(input())
if choice == 1:
print("Enter destination: ")
destination = input()
flag = False
for line in my_file:
if destination in line:
print(line)
flag = True
if not flag:
print("No such root found")
elif choice == 2:
for line in my_file:
my_list = line.split()
if int(my_list[4]) < 50:
print(line)
elif choice == 0:
check = False
else:
print("Wring symbol")
my_file.close()
except:
print("Wring symbol")
-----------------------------------------------------------------------------------------------------------
my_file = open("file_4.txt")
my_dict = dict()
for line in my_file:
my_list = line.split(maxsplit=1)
sum = 0
num = ""
for char in my_list[1]:
if char.isdigit():
num = num + char
else:
if num != '':
sum += int(num)
num = ''
if num != '':
sum += int(num)
my_dict[my_list[0][:len(my_list[0])-1]] = sum
my_file.close()
print(my_dict)
-----------------------------------------------------------------------------------------------------------
my_file = open("file_5.txt")
my_list = [dict(), dict()]
counter = sum = 0
for line in my_file:
list1 = line.split()
if int(list1[2])- int(list1[3]) >= 0:
sum += int(list1[2])-int(list1[3])
counter += 1
my_list[0][list1[0]] = int(list1[2])-int(list1[3])
my_file.close()
try:
my_list[1]["average income"] = sum/counter
except ZeroDivisionError:
my_list[1]["average income"] = 0
print(my_list)
Editor is loading...