hey again,
I wrote this code.. very quickly and messily.
I would like to 'clean' it up.. that is put some functions in it.
def numWords(aString):
lst = aString.split()
noword = 0
for word in lst:
noword = noword + 1
return noword
def save
inp = raw_input("Please enter some words: ")
total = 0
total = numWords(inp)
words = "File has %d words" % total
print words
choice = raw_input("Would you like to save the file?(y/n): ")
if choice == 'y' and 'ye' and 'yes':
save = str( raw_input("What would you like to save it as.(file.txt: "))
import os
if os.path.exists(save):
overwrite = raw_input("Would you like to overwrite file?")
if overwrite == 'y' and 'ye' and 'yes':
f = file(save,'w')
f.write(inp + '\n' + words)
f.close()
else:
save2 = raw_input("Would you like to save it under a different name? ")
if save2 == 'y' and 'ye' and 'yes':
save = str( raw_input("What would you like to save it as.(file.txt: "))
f = file(save,'w')
f.write(inp + '\n' + words)
f.close()
else:
f = file(save,'w')
f.write(inp + '\n' + words)
f.close()
else:
print "Discarding unsaved changes..."
raw_input("Press Enter to exit.......")
Can someone give me some ideas, but not give it away so that I may try and figure it out myself?
THANKS,
Jem