Beginner Python 3.3.2 - How do I use .replace() from a file?
Let's say I have a .txt file that contains the following information:
a g
b j
d l
e o
q p
How do I make a program that asks the user for input (a string) and swaps
the first letter with the corresponding letter next to it. Example output:
Enter string: Jelly bean queen
Swapped: Joddy jogn puoon
My code so far is this:
input1 = input("Enter string: ")
a1 = "" #A1 refers to the first column of letters
a2 = "" #A2 refers to the second column of letters
with open("text_file.txt") as f:
for line in f:
a1 = a1 + line[0] #Adds the first letters to A1
a2 = a2 + line[2] #Adds the second letter to A2
I tried lots of things after that but none seemed to work, most of my
attempts don't make any sense. I'd ask my tutor for help but they are all
busy and I don't want to bother them anymore lol. Sorry for my newbieness.
If anyone needs further clarification just ask.
No comments:
Post a Comment