Question 1

Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number.

Question 2

A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a file. The program should output the unique words and their frequencies in alphabetical order.

Question 3

A list is sorted in ascending order if it is empty or each item except the last one is less than or equal to its successor. Define a function isSorted that expects a list as an argument and returns True if the list is sorted, or returns Falseotherwise. (Hint : For a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return False if the first item in a pair is greater.)

Question 4

Define and test a function myRange. This function should behave like Pythons standard range function, with the required and optional arguments, but should return a list. Do not use the range function in your implementation! Hints:

  • Study Pythons help on range to determine the names, positions, and what to do with your functions parameters.
  • Use a default value of None for the two optional parameters. If these parameters both equal None, then the function has been called with just the stop value. If just the third parameter equals None, then the function has been called with a start value as well. Thus, the first part of the functions code establishes what the values of the parameters are or should be. The rest of the code uses those values to build a list by counting up or down.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.