Answer to Question #52285 in Python for seid

Question #52285
Question 1

Write a program, question1.py, where the user can input student numbers of students in a class and the program writes this data to a file called “question1.out”. All student numbers are 9 characters long. The input will end with the word DONE. The question1.out file must have each student number on a new line, exactly as in the example below:

Example question1.out:
APPLES001
ORNGES002
BNNASH004
KWSBLE005
PRSSON003

Question 2

Write a program, question2.py, to read in the file “question1.out” saved above, and output a new file called “question2.out”. This new file should have the student numbers sorted in alphabetical order:

Examplequestion2.out:
APPLES001
BNNASH004
KWSBLE005
ORNGES002
PRSSON003
1
Expert's answer
2015-06-04T03:36:08-0400
Problem.
Question 1


Write a program,question1.py, where the user can input student numbers of students in a class
and the program writes this data to a file called “question1.out”. All student
numbers are 9 characters long. The input will end with the word DONE. The
question1.out file must have each student number on a new line, exactly as in
the example below:

Example question1.out:
APPLES001
ORNGES002
BNNASH004
KWSBLE005
PRSSON003

Question 2 

Write a program, question2.py, to read in thefile “question1.out” saved above, and output a new file called “question2.out”.
This new file should have the student numbers sorted in alphabetical order:

Examplequestion2.out:
APPLES001
BNNASH004
KWSBLE005
ORNGES002
PRSSON003
 
Code (Question 1).
fout = open('question1.out', 'w')
 
while True:
    student_number = input()
    if student_number == "DONE":
        break
    else:  
        fout.write(student_number + )
 
Code(Question 2).
fin = open('question1.out', 'r')
fout = open('question2.out', 'w')
list = []
 
for line in fin:
    list.append(line.strip())
 
list.sort()
   
for student_number in list:
    fout.write(student_number + "\n")
 
question1.out
APPLES001
ORNGES002
BNNASH004
KWSBLE005
PRSSON003
 
question2.out
APPLES001
BNNASH004
KWSBLE005
ORNGES002
PRSSON003
 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS