0

hey could you please help me :(
(((write a function called acronym which read a file which contains words, and create an acronym by taking the first letters of the words in a phrase and making a word from t hem. Then save all acronyms to a file called myacronym.txt.)))

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Member 784833
0

def mine():
x=raw_input("Enter the file name: ")
y=raw_input("enter the file name: ")
inFile=open(x,'r')
outFile=open(y,'w')
for line in inFile:
z1,z2,z3,z4=string.split(line,' ')
a=z[0]+z2[0]+z3[0]+z4[0]+z5[0]
outFile.write(a+'\n')
inFile.close()
outFile.close()
mine()

0
def mine():
    x=raw_input("Enter the file name: ")
    y=raw_input("enter the file name: ")
    inFile=open(x,'r')
    outFile=open(y,'w')
    for line in inFile:
        z1,z2,z3,z4=string.split(line,' ')
        a=z[0]+z2[0]+z3[0]+z4[0]+z5[0]
        outFile.write(a+'\n')
    inFile.close()
    outFile.close()
mine()

You forgot to put code-tags

Edited by mike_2000_17: Fixed formatting

0

You have variable z1, but line 8 you use z.

Why should there be exactly four words in each line?

Would it not be better to loop over all words irrespective how many they are:

for word in line.split():
0

thank you so much
but i tried the function but it does not work
a=z[0]+z2[0]+z3[0]+z4[0]+z5[0]
NameError: global name 'z' is not defined

i have a file that the function should reads all the line each line has from 3 to 5 words .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.