Arora
Arora

Reputation: 29

In python I am not able to export the output in text format

I have two string and I am trying to match each position and providing a symbol accordingly. I am very new to python and facing an issue with exporting the file. I am getting output but when I am exporting the same it gave None as out. The string look like this.

def up():
    for i in range (s3):
        if bp1[i]==bp2[i]:
            print("(", end="")
        else:
            print(".", end="")
ax = up()
with open('putt.txt', 'w') as a:
print(ax, file = a)

Upvotes: 1

Views: 194

Answers (1)

SM Abu Taher Asif
SM Abu Taher Asif

Reputation: 2331

your function doesn't return anything. return the string then write and lopp should run for length of bp1 :

bp1 = "ASDFGHJKL"
bp2 = "AS_FG_JKL"

def up():
    data = ""
    for i in range (len(bp1)):
        if bp1[i]==bp2[i]:
            data = data + ")"
        else:
            data = data + "."
    return data
ax = up()
with open('putt.txt', 'w') as f:
    for line in ax:
        f.write(line)

Upvotes: 1

Related Questions