0

So I've written this code:

#input and output files
infile = open("unsorted_fruits.txt", "r")
outfile = open("sorted_fruits.txt","w")

#reading infile
Fruits = infile.read()

#time to sort the fruit
Fruits = Fruits.split()
Fruits.sort()

for fruit in Fruits:
    if fruit != "\n":
        outfile.write(fruit) #putting fruit in the output file

#closing files        
infile.close()
outfile.close()

And, now I am trying to write pseudocode for it. I am having trouble getting pass the first line. I don't know how to word it? And every time I try to get help from the internet, bubble sort pops up, and I don't think that's correct. I could be wrong though.. Any input would be helpful. So far all I have before I get stuck is:

BEGIN insert both file names
READ unsorted_fruits.txt
EXECUTE
  • are you saying that you dont actually know what your code is doing? – WildCard May 26 '16 at 03:00
  • No, I wrote my code before I did pseudo. I know exactly what my code is doing. I just don't use pseudo, I'm always making flowcharts, so I wanted to try, but I'm not understanding it. I know it'd be a simple pseudocode, but I'm confused on how to do it. I've read just about everything, but I am not understanding how to write pseudo for something like this: two files and alphabetical order. – Brette Young May 26 '16 at 03:07

1 Answers1

0

This process is entirely up to your wants and needs, unless you are doing a school project with specific guidelines.

going off of what you already have:

BEGIN insert both file names
READ unsorted_fruits.txt
ASSIGN lines in unsorted_fruits to variable Fruits
TURN Fruits into a list
SORT list of Fruits
ITERATE through list items(Fruits)
IF list item(Fruits) is anything but a newline, write 
to outfile(sorted_fruits.txt)
CLOSE files
WildCard
  • 527
  • 3
  • 8
  • This is incredibly helpful. It's allowing me to line the two up and see exactly what is going on. I'll be referencing back to this whenever I flowcharting/pseudo-ing. It's a perfect example, I thank you to the moon! – Brette Young May 26 '16 at 03:25
  • Im glad I could help – WildCard May 26 '16 at 03:30