Main.Assignment6 History
Hide minor edits - Show changes to markup
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).
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.
print "average number of words per sentence in your file is:", average
# display the result
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.
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).
file_name = ask_for_input_file()
# code for handling the file_name
Assignment 5
Assignment 6
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:)
- 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.
