On 21/10/2013 01:16, Sammy Cornet wrote:
Hello!
I'm using python 2.7.5 version and I'm trying to write a program related
to a file named unsorted_fruits.txt contains a list of 26 fruits, each
one with a name that begins with a different letter of the alphabet. My
program's goal is to read in the fruits from the file
unsorted_fruits.txt and writes them out in alphabetical order to a file
named sorted_fruits.txt while I'm using while loop
For this assignment you must incorporate the use of a list, for loop and
/ or while loop.
so here is what I have on my script:
infile = open('Desktop/unsorted_fruits.docx' ,"r")
outfile = open('Desktop/sorted_fruits.docx', 'w')
def find():
index = 0
while index < 26:
list < 26
list = ["a", "b", "c", "e", "f", "g", "h", "i", "j", "k", "l",
"m", "n" "o", "p", "q", "r", "s", "t", "u", "v", "w", "z", "y", "z"]
if index[0] == list[0]:
infile = list + 1
print infile
index += 1
infile.close()
outfile.close()
And here is my output:
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART
================================
>>>
Traceback (most recent call last):
File "F:/7.real.py", line 1, in <module>
infile = open('Desktop/unsorted_fruits.docx' ,"r")
IOError: [Errno 2] No such file or directory: 'Desktop/unsorted_fruits.docx'
>>>
Once you have fixed the file name error which Steven has already pointed
out, do you intend to call the function find that you have defined? If
yes can I suggest that you use paper and pencil to work out what it
does, or more accurately doesn't do, as it's strewn with errors.
--
Python is the second best programming language in the world.
But the best has yet to be invented. Christian Tismer
Mark Lawrence
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor