PYTHON

profileschoolanswers

PROGRAM A:
This program should use a main function and another function named makelist as follows:

  • in main, generate a random integer that is greater than 5 and less than 13.
  • print this number on its own line.
  • call the makelist function with the random integer as sole argument.
  • inside the makelist function:
    • make an empty list.
    • use a loop to append to the list a number of elements equal to the random integer argument. All new list elements must be random integers ranging from 1 to 100, inclusive. Duplicates are okay.
    • return the list to main.
  • back in main, catch the returned list and sort it.
  • finally, use a for loop to display the sorted list elements, all on one line, separated by single spaces.

SAMPLE OUTPUT
List size will be 7
Here is the sorted list:
8 28 35 41 51 62 72

ANOTHER SAMPLE OUTPUT
List size will be 10
Here is the sorted list:
3 3 9 20 36 43 48 50 81 93

PROGRAM B:
Use the text file named scores.txt (supplied). It contains a number of integer test scores, one per line. Your program should use a main function and another function named showscores as follows:

  • in main, create an empty list.
  • open the file named scores.txt.
  • use a while loop that can detect the end of file to read the scores, and add them to the list.
  • close the file.
  • call the showscores function with the list of scores as sole argument.
  • inside the showscores function:
    • process the list of scores. NOTE: your instructor will use a modified version of scores.txt with different scores and a different number of scores. Your code should be capable of handling this.
    • print out the average score accurate to two decimal places.

Create a folder that identifies you and Assignment 1 such as smith_asst1 or asst1_jones. Save all files to this folder. Omit the text file.Zip the folder. No .rar files allowed. Upload the zip to the Assignment 1 drop box.

    • Posted: 5 years ago
    • Due: 
    • Budget: $20