Reputation: 29
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
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