Question

Exercise 7: Program exercise for Basic List operations Write a complete Python program including minimal comments (ile name,

0 0
Add a comment Improve this question Transcribed image text
Answer #1


check out the solution and do comment for any queries.
------------------------------------------------

# file name : listop.py
# name :
# program description : demonstration of basic list operations

# function definition
def main():
# initialize the list
lst = []
  
# infinite loop
while(1):
# prompt for user input
print("enter a score : ")
# read user input
n = input()
# check for empty input
if n:
# if not empty then convert to 'int' and append to the list
lst.append(int(n))
else:
# if empty then break out of the loop
break
# print the scores entered
print("\nAll scores stored : ", lst)
# find the length of the list
length = len(lst)
# if list is empty then print some message
if length==0 :
print("No scores entered")
else:
# if list not empty then print accordingly
print("\nThere are", length, "scores entered")
# loop through list and find sum
s = 0
for element in lst:
s += element
# finds average
average = s/length
# print average with 2 digits after decimal point
print("\nThe average is : %.2f" %average)
# sort the list
slst = sorted(lst)
# print th sorted list
print("\nAfter sorting in ascending oder : ", slst)
# sort the list in reverse
rslst = sorted(lst, reverse = True)
  
# print the scores with ranking starting with 1
rank=1
print("\nrank\t\t:\t\tscore\n")
for element in rslst:
print(rank,"\t\t:\t\t" ,element)
rank += 1
  
# main function call
if __name__== "__main__":
main()

---------------------

code:

1# file name : Listop.py 2 # name : 3 # program description : demonstration of basic list operations 5# function definition 6if length==0 : print(No scores entered) else: # if list not empty then print accordingly print(\n There are, length, scor----------------

Output 1::

enter a score : enter a score : 97 enter a score : 77 enter a score : All scores stored : [89, 97, 77] There are 3 scores ent

Output 2 ::

enter a score : All scores stored : [] No scores entered

Add a comment
Know the answer?
Add Answer to:
Exercise 7: Program exercise for Basic List operations Write a complete Python program including minimal comments...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file...

    Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file name, your name, and problem description) that solves the following problem with the main function: Problem Specification: The following code reads values from the file object infile and stores them in the 2d list table2: (It assumes that each line contains values of elements in each row and the values are whitespace separated.) table2 = [] for line in infile: row=line.split() intRow = []...

  • SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes...

    SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array....

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • write a program that uses a function to read in the grades for four classes and...

    write a program that uses a function to read in the grades for four classes and then uses a function to calculate the average grade in each of the classes. input the grades for one student. we will name her Beverly. output how Beverly's grade differs from each classe average. Make sure that your output is very clear. Below is your data: English 90 70 85 45 95 95 82 97 99 65 History 63 94 60 76 83 98...

  • Python Basic Lists, File IO, Exception Handling 1. Call createTable() to: Read in the data from...

    Python Basic Lists, File IO, Exception Handling 1. Call createTable() to: Read in the data from each of the input files (in order from scores1.txt to scores5.txt) and store the data in table. The table is a list of lists, where the scores of each input file is a column of data of the table. By the end of the function, the table should have 5 columns of numbers, each column is from one input file. Here is the first...

  • Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding...

    Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding each answer to the nearest whole number. Using the frequency distribution below (scores on a statistics exam taken by 80 students), determine:ion 1 of the preliminary test (scores on a statistics exam taken by 80 students), determine: 68 84 75 82 68 90 62 88 76 93 73 79 88 73 60 93 71 59 85 75 61 65 75 87 74 62 95...

  • Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding...

    Use the Grouped Distribution method for the following exercise (see Self-Test 2-4 for detailed instructions), rounding each answer to the nearest whole number. Using the frequency distribution below (scores on a statistics exam taken by 80 students), determine:ion 1 of the preliminary test (scores on a statistics exam taken by 80 students), determine: 68 84 75 82 68 90 62 88 76 93 73 79 88 73 60 93 71 59 85 75 61 65 75 87 74 62 95...

  • Please help me with this program.You are to write a C++ program that will read in...

    Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT