In: Computer Science
Python Code:
If the GPA is >= 3.5, display 'Dean’s List'
If the GPA is < 2.0, display 'Dismissed’
If the GPA is < 3.5 and >= 2.0, display 'Regular Standing'
The data is as follows:
Mohammed James 012345 94 3.2
Priya Jones 112245 45 3.9
George Wayne 013265 18 1.9
Jennifer Fulton 121378 30 2.0
Ayesha Smith 043245 64 3.5
Answer 1:(code for first file)
class Student(object):
def __init__(self, fname, lname, stud_id, hours, gpa):
self.name = fname + ' ' + lname
self.stud_id = stud_id
self.hours = hours
self.gpa = gpa
def getgpa(self):
return self.gpa
def getid(self):
return self.stud_id
def gethours(self):
return self.hours
def __str__(self):
return self.name + ' : ' + str(self.getid()) +' ::' + str(self.gethours()) +' :: '+ str(self.getgpa())
# Defining a function for building a Record
# which generates list of all the students
def Markss(Record, fname, lname, stud_id, hours, gpa):
Record.append(Student(fname, lname, stud_id, hours, gpa))
return Record
# Main Code
Record = []
x = 'y'
while x == 'y':
fname = input('Enter the first name of the student: ')
lname = input('Enter the last name of the student: ')
stud_id = input('Enter the student id: ')
hours = input('Hours: ')
gpa = input('GPA: ')
Record = Markss(Record, fname, lname , stud_id, hours, gpa)
RecordForFile = fname + ' ' + lname + ' ' + stud_id + ' ' + hours + ' ' + gpa
file = open('read.txt', 'a+')
newRec = str(RecordForFile)
file.write(newRec+ "\n")
file.close()
x = input('another student? y/n: ')
# Printing the list of student
n = 1
for el in Record:
print(n,'. ', el)
n = n + 1
Output:
Answer 2:(Code for second file)
print ("FirstName LastName StudId Hours GPA Qualification")
file1 = open("read.txt","r+")
Record = file1.read()
x = Record.split()
n=1
for el in x:
if n == 6 or n == 11 or n == 21:
print(el, end='\t ')
else:
print(el, end='\t')
if n % 5 == 0 :
if float(el) >= 3.5:
print("Dean's List")
elif float(el) < 2.0 :
print("Dismissed")
elif float(el) < 3.5 and float(el) >= 2.0 :
print("Regular Standing")
n=n+1
Output: