In: Computer Science
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:
Your program will contain at least three (3) functions - main, getInfo, and compute - that complete the following tasks:
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
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()