IT 117: Introduction to Scripting
Homework 3

Due

Sunday, February 12th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Functions

open_file_read

student_dictionary_create

student_dictionary_print

Test Code

filename = input("File name: ")
file = open_file_read(filename)
if file:
	students = student_dictionary_create(file)
	if students:
		student_dictionary_print(students)

Output

Suggestions

  1. Create the file hw3.py.
    Enter the headers for open_file_read, student_dictionary_create and student_dictionary_print.
    Under each header write the Python statement pass.
    Run the script.
    Fix any errors you find.
  2. Replace the pass statement in open_file_read with the body of the code from your hw2.py.
    Copy the test code into the bottom of the file.
    Comment out all but the first two lines.
    Run the scrip entering both a real filename and the name of a file that does not exists.
    Fix any errors you find.
  3. Remove the pass statement in student_dictionary_create.
    Replace it with a for loop on file using line as the loop variable.
    Inside the loop, print line.
    Uncomment the next two lines in the test code..
    Run the script entering full_student_data.txt when prompted.
    Fix any errors you find.
  4. Remove the print statement.
    Create the list variable fields by calling the split method on line.
    If you are not sure what I mean, see Class Exercise 2.
    Print the value of fields.
    Run the script.
    Fix any errors you find.
  5. Remove the print statement.
    Create the variables id, first, last, user and email from fields using indexing.
    Again, see Class Exercise 2 for examples.
    Print these new variables.
    Run the script.
    Fix any errors you find.
  6. Remove the print statement.
    Create the tuple data containing the values of first, last, user and email.
    Print this tuple.
    Run the script.
    Fix any errors you find.
  7. Remove the print statement.
    Above the for loop, create the empty dictionary students.
    As the last statement in the for loop, create an entry in students with id as the key and data as the value,
    Outside the for loop print students.
    Run the script.
    Fix any errors you find.
  8. Remove the print statement.
    Replace it with a return statement that returns students.
    In student_dictionary_print replace the pass statement that prints the parameter students.
    Uncomment the last two lines in the test code.
    Run the script.
    Fix any errors you find.
  9. Remove the print statement.
    Replace it with a for loop over students using id as the loop variable.
    The loop should be sorted by id.
    Inside the for loop print id.
    Run the script.
    Fix any errors you find.
  10. Remove the print statement.
    Create the tuple variable data from the value associated with id in the students dictionary.
    Create the variables first, last, user and email from data using indexing.
    Print id, first, last, user and email on a single line.
    Run the script.
    Fix any errors you find.

Testing on Your Machine

Copy the Script to Unix

Testing the Script on Unix (Optional)

Copyright © 2020 Glenn Hoffman. All rights reserved. May not be reproduced without permission.