Как по данному коду создать файл

Наталья

Новичок
Пользователь
Май 31, 2020
3
0
1
В Windows, Python 3.8.
Python:
with open('d:/1.txt', 'r') as f1:
    full_txt1 = f1.readline().split(' ')
    print(full_txt1)
 
with open('d:/2.txt', 'r') as f2:
    full_txt2 = f2.readline().split(' ')
    print(full_txt2)
# цикл на одинаковость.
    for i in full_txt1:
        if i in full_txt2:
            with open('d:/3.txt', 'a') as s1:
                print(i, file=s1)
# цикл на наличие только в первом файле.
    for i in full_txt1:
        if i not in full_txt2:
            with open('d:/4.txt', 'a') as s2:
                print(i, file=s2)
    txt1 = str()
    txt2 = str()
    for i in full_txt1:
        if full_txt1.count(i) > 1:
            txt1 = i
    for i in full_txt2:
        if full_txt2.count(i) > 1:
            txt2 = i
 
    print(txt1)
    print(txt2)
 
    with open('d:/5.txt', 'a') as s3:
        print(txt1,txt2, file=s3)
    with open('d:/1.txt', 'r') as f1:
         full_txt1 = f1.readline().split(' ')
    print(full_txt1)
 
with open('d:/2.txt', 'r') as f2:
    full_txt2 = f2.readline().split(' ')
    print(full_txt2)
# цикл на одинаковость.
    for i in full_txt1:
        if i in full_txt2:
            with open('d:/3.txt', 'a') as s1:
                print(i, file=s1)
# цикл на наличие только в первом файле.
    for i in full_txt1:
        if i not in full_txt2:
            with open('d:/4.txt', 'a') as s2:
                print(i, file=s2)
    txt1 = str()
    txt2 = str()
    for i in full_txt1:
        if full_txt1.count(i) > 1:
            txt1 = i
    for i in full_txt2:
        if full_txt2.count(i) > 1:
            txt2 = i
 
    print(txt1)
    print(txt2)
 
    with open('d:/5.txt', 'a') as s3:
        print(txt1,txt2, file=s3)
    with open('d:/1.txt', 'r') as f1:
         full_txt1 = f1.readline().split(' ')
    print(full_txt1)
 
with open('d:/2.txt', 'r') as f2:
    full_txt2 = f2.readline().split(' ')
    print(full_txt2)
# цикл на одинаковость.
    for i in full_txt1:
        if i in full_txt2:
            with open('d:/3.txt', 'a') as s1:
                print(i, file=s1)
# цикл на наличие только в первом файле.
    for i in full_txt1:
        if i not in full_txt2:
            with open('d:/4.txt', 'a') as s2:
                print(i, file=s2)
    txt1 = str()
    txt2 = str()
    for i in full_txt1:
        if full_txt1.count(i) > 1:
            txt1 = i
    for i in full_txt2:
        if full_txt2.count(i) > 1:
            txt2 = i
 
    print(txt1)
    print(txt2)
 
    with open('d:/5.txt', 'a') as s3:
        print(txt1,txt2, file=s3)
    with open('d:/1.txt', 'r') as f1:
         full_txt1 = f1.readline().split(' ')
    print(full_txt1)
 
with open('d:/2.txt', 'r') as f2:
    full_txt2 = f2.readline().split(' ')
    print(full_txt2)
# цикл на одинаковость.
    for i in full_txt1:
        if i in full_txt2:
            with open('d:/3.txt', 'a') as s1:
                print(i, file=s1)
# цикл на наличие только в первом файле.
    for i in full_txt1:
        if i not in full_txt2:
            with open('d:/4.txt', 'a') as s2:
                print(i, file=s2)
    txt1 = str()
    txt2 = str()
    for i in full_txt1:
        if full_txt1.count(i) > 1:
            txt1 = i
    for i in full_txt2:
        if full_txt2.count(i) > 1:
            txt2 = i
 
    print(txt1)
    print(txt2)
 
    with open('d:/5.txt', 'a') as s3:
        print(txt1,txt2, file=s3)
 

Форум IT Специалистов