Question

In: Computer Science

1D List Practice Could you write the code to solve the following problem that uses 1D...

1D List Practice

Could you write the code to solve the following problem that uses 1D lists?

You have been tasked with writing a Python program that will assist the CAU Registrar’s Office with determining the following:

  • the average GPA of the freshman class after their first semester
  • the top five GPAs
  • the number of students who are eligible for the Dean’s List (i.e., their GPA is 3.25 or higher)

Your program will contain at least three (3) functions - main, getInfo, and compute - that complete the following tasks:

  • a function named main that “kicks off” the program with a description of what the program will do. It will then call the getInfo function (see below).
  • a function named getInfo reads the file named freshmen.txt and puts the GPAs of the freshman class into a list (named students). This function will then call (with the list as the argument) the compute function (see below).
  • a function compute will calculate and display (to the screen):
    • the average GPA of the freshman class after their first semester
    • the top five GPAs
    • the number of students who are eligible for the Dean’s List (i.e., their GPA is 3.25 or higher)

Note: To test/run your program, you will need to generate a file named freshmen.txt that contains 450 GPAs (each on its own line) that have been randomly generated, ranging from 1.0 to 4.0

Solutions

Expert Solution

please give thumbs up, thanks

sample output with code:

code:


@author: VISHAL
"""
import random
def createfile():
f=open("freshmen.txt","w");
for i in range(450):
number=random.uniform(1,4);
f.write(str(number) + "\n");
f.close();

def getInfo():
f=open("freshmen.txt","r");
students=list();
lines=f.readlines();
f.close();
for i in lines:
students.append(float(i))
compute(students)
  
def compute(students):
n=len(students);
S=0.0;
count=0;
for i in students:
S=S+i;
if(i>=3.25):
count=count+1;
average=S/n;
students.sort(reverse=True);
top_5_GPA=students[0:5];
print("Average GPA: ",average);
print("Top 5 GPA : ",top_5_GPA);
print("Number of students who are eligible for the Dean’s List : ",count)
def main():
createfile();
getInfo();
  
main()


Related Solutions

write the pseudocode and code to solve the following: you are given a list. determine the...
write the pseudocode and code to solve the following: you are given a list. determine the sum of all the elements in the list without using the built in puthon function sum(). Take your code and create your own function and name it my_sum_algo() which will return the sum of numbers PS please write comments in the code for my understanding, and please write jn jn PYTHON 3 languge. Thank you, have a great day !
Please use C programming to write the code to solve the following problem. Also, please use...
Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially: void inputStringFromUser(char *prompt, char *s, int arraySize); void songNameDuplicate(char *songName); void songNameFound(char *songName); void songNameNotFound(char *songName); void songNameDeleted(char *songName); void artistFound(char *artist); void artistNotFound(char *artist); void printMusicLibraryEmpty(void); void printMusicLibraryTitle(void); const int MAX_LENGTH = 1024; You will write a program that maintains information about your...
Write pseudo-code to solve the following problem using MapReduce and explain how it works. Each line...
Write pseudo-code to solve the following problem using MapReduce and explain how it works. Each line in the file lists a user ID, the ID of the movie the user watched, the rating the user gave for the movie, and the timestamp. For example line 1 indicates that the user’s ID is 196, the movie ID is 242, the user gave this movie a rating of 3, and the timestamp is 881250949. Given the file, find out the top similar...
I just wrote Python code to solve this problem: Write a generator that will return a...
I just wrote Python code to solve this problem: Write a generator that will return a sequence of month names. Thus gen = next_month('October') creates a generator that generates the strings 'November', 'December', 'January' and so on. If the caller supplies an illegal month name, your function should raise a ValueError exception with text explaining the problem. Here is my code: month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def next_month(name: str) -> str:...
Java Generic 2D Linked List Problem How to convert a 1D linked List into multiple linked...
Java Generic 2D Linked List Problem How to convert a 1D linked List into multiple linked lists with sequential values together? //Example 1: [1,1,2,3,3] becomes [[1,1],[2],[3,3]] //Example 1: [1,1,2,1,1,2,2,2,2] becomes [[1,1],[2],[1,1],[2,2,2,2]] //Example 3: [1,2,3,4,5] becomes [[1],[2],[3],[4],[5]] public <T> List<List<T>> convert2D(List<T> list) { // Given a 1D, need to combine sequential values together. }
Write a complete and syntactically correct Python program to solve the following problem: You are the...
Write a complete and syntactically correct Python program to solve the following problem: You are the payroll manager for SoftwarePirates Inc. You have been charged with writing a package that calculates the monthly paycheck for the salespeople. Salespeople at SoftwarePirates get paid a base salary of $2000 per month. Beyond the base salary, each salesperson earns commission on the following scale: Sales Commission Rate Bonus <$10000 0% 0 $10000 – $100,000 2% 0 $100,001 - $500,000 15% $1000 $500,001 -...
Design a three part, 1D, Kinematics problem, Solve it (finding the total time and distance traveled)...
Design a three part, 1D, Kinematics problem, Solve it (finding the total time and distance traveled) and show it x(t), v(t), a(t) graph. make the initial x(t) as zero but the initial v(t) can not be zero. for example, you could start at a constant speed, then slow to a stop, then speed up in the same direction (or go in reverse). Or you could start at certain speed, immediately speed up, then stay at that new speed for (say...
A: Write a divide-and-conquer program to solve the following problem:
in Java A: Write a divide-and-conquer program to solve the following problem:     1. Let A[1..n] and B[1..n] be two arrays of distinct integers, each sorted in an increasing order.      2. Find the nth smallest of the 2n combined elements. Your program must run in O(log n) time. For example: n = 4If A[1..n] = {2, 5, 8, 9} and B[1..n] = {1, 4, 6, 7}The nth (i.e. 4th) smallest integer is 5.If A[1..n] = {2, 5, 8, 13}...
Write a python script to solve the 4-queens problem using. The code should allow for random...
Write a python script to solve the 4-queens problem using. The code should allow for random starting, and for placed starting. "The 4-Queens Problem[1] consists in placing four queens on a 4 x 4 chessboard so that no two queens can capture each other. That is, no two queens are allowed to be placed on the same row, the same column or the same diagonal." Display the iterations until the final solution Hill Climbing (your choice of variant)
What could happen if you are analyzing some data to solve an engineering problem, but the...
What could happen if you are analyzing some data to solve an engineering problem, but the data was not taken correctly and does not represent the population size?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT