Main.Assignment6 History

Hide minor edits - Show changes to markup

March 01, 2010, at 12:45 PM MST by 10.84.44.69 -
Changed lines 7-10 from:

Write a function called avg_words_per_sentence(file_name) that computes the average number of words per sentence in the given file, which is assumed to contain English text.

Call your program words_per_sentence.py. It should be runnable as a script as: python words_persentence.py file_name. To access command-line arguments use sys.argv as discussed in the lab. If the given file name does not exist, print a message and exit (you can use sys.exit() in your program to do so).

to:

Write a function called avg_words_per_sentence(file_name) that returns the average number of words per sentence in the given file, which is assumed to contain English text.

Call your program words_per_sentence.py. It should be runnable as a script as: python words_persentence.py file_name. To access command-line arguments use sys.argv as discussed in the lab. If the given file name does not exist, print a message and exit (you can use sys.exit() in your program to do so). Your program should print a message with the result of running avg_words_per_sentence:

The average number of lines per sentence in the file xxx is yyy.

Changed line 23 from:
   print "average number of words per sentence in your file is:", average
to:
   # display the result
February 28, 2010, at 06:57 PM MST by 71.196.160.210 -
Changed lines 9-10 from:

Call your program words_per_sentence.py. When run as a script your program should ask the user for a file name. It should verify that the file exists, and keep asking the user for a file name until the user provides a proper file name.

to:

Call your program words_per_sentence.py. It should be runnable as a script as: python words_persentence.py file_name. To access command-line arguments use sys.argv as discussed in the lab. If the given file name does not exist, print a message and exit (you can use sys.exit() in your program to do so).

Changed line 19 from:
   file_name = ask_for_input_file()
to:
   # code for handling the file_name
February 28, 2010, at 01:02 PM MST by 71.196.160.210 -
Changed line 1 from:

Assignment 5

to:

Assignment 6

February 28, 2010, at 01:02 PM MST by 71.196.160.210 -
Added lines 1-24:

Assignment 5

Due date: 3/8/10

Average number of words in a sentence

Write a function called avg_words_per_sentence(file_name) that computes the average number of words per sentence in the given file, which is assumed to contain English text.

Call your program words_per_sentence.py. When run as a script your program should ask the user for a file name. It should verify that the file exists, and keep asking the user for a file name until the user provides a proper file name.

Structuring your program

Your program should be structured as follows: (:source lang=python:)

  1. all the function definitions go here

if __name__ == _main_ :

   file_name = ask_for_input_file()
   average = avg_words_per_sentence(file_name)
   print "average number of words per sentence in your file is:", average

(:sourceend:)

Include an identifying comment as usual, plus comments that explain how your code works.