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.)))

Recommended Answers

All 6 Replies

What you have written until now?

Smells like homework simple enough to do yourself.

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()

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

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():

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 .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.