Python Program: Design the logic for and implement a program that merges the two files into one text file (.txt) containing a list of all students, maintaining ID number order. At the end of the text file provide descriptive data that lists a count of students in each major, the average GPA for each major, and a count and average GPA for the whole program. The data files are already sorted in student ID order. Your program should create a merged file called 'DeptStudentMerge.txt'. Use the default folder as the file location (do NOT list out a path on your own computer or request a path). Here's the program I have so far and the dataset in on the bottom.
CINSMajors
214, Davis, Kimberly, 3.4
315, Thompson, Hunter, 2.9
319, Harris, Michael, 2.3
320, Nichols, Matthew, 3.5
322, Pohler, Geoffrey, 4.0
412, Max, Manfreid, 3.2
PBISMajors
202, Kennedy, Lincoln, 2.4
306, Laslow, Bernard, 2.5
393, Nuance, Deborah, 2.6
395, Samson, Michelle, 3.1
#Declarations
CINSFile = ''
PIBSFile = ''
DeptStudentMergeFile = ''
CINSRecord = []
PIBSRecord = []
count = 0
END_NAME = 'ZZZZZ'
areBothAtEnd = 'N'
def ReadCINS(CINSFile):
global CINSRecord
CINSRecord = CINSfile.readline().rstrip('\n').split(',')
if CINSRecord[0] == '':
CINSRecord[0] = END_NAME
def ReadPIBS(PIBSFile):
global PIBSRecord
PIBSRecord = PIBSfile.readline().rstrip('\n').split(',')
if PIBSRecord[0] == '':
PIBSRecord[0] == END_NAME
def CheckEnd(CINSFile, PIBSFile):
global areBothAtEnd
if CINSRecord[0] == END_NAME:
if PIBSRecord[0] == END_NAME:
areBothAtEnd = 'Y'
def GetReady():
global CINSFile
global PIBSFile
global DeptStudentMergeFile
global areBothAtEnd
CINSFile = open('CINSData.txt', 'r')
PIBSFile = open('PIBSData.txt', 'r')
DeptStudentMergeFile = open('DeptStudentMerge.txt', 'w')
def FinishUp(CINSFile, PIBSFile, DeptStudentMergeFile):
CINSFile.close()
PIBSFile.close()
DeptStudentMergeFile.close()
def MergeRecords(CINSFile, PIBSFile,
DeptStudentMergeFile):
global CINSRecord
global PIBSRecord
outputline = float()
CINSRecord = ReadCINS(CINSFile)
PIBSRecord = ReadPIBS(PIBSFile)
areBothAtEnd = CheckEnd(CINSFile, PIBSRecord)
if CINSRecord[0] < PIBSRecord[0]:
outputline = CINSRecord[0] + ',' float(CINSRecord[1] + '\n'
CINSFile = ReadCINS(CINSFile)
else:
outputline = PIBSRecord[0] + ',' + float(PIBSRecord[1]) +
'\n'
PIBSFile = ReadPIBS(PIBSFile)
DeptStudentMergeFile.write(outputline)
areBothAtEnd = CheckEnd(CINSFile, PIBSFile)
def Main():
#Mainline logic
CINSFile, PIBSFile, DeptStudentMergeFile = GetReady()
while areBothAtEnd != 'Y':
MergeRecords()
FinishUp(CINSFile, PIBSFile, DeptStudentMergeFile)
if __name__== '__main__':
Main()
f1 = open("cins.txt", "r")
f2=open("pibs.txt","r")
f3=open("combine.txt","a")
dict={}
first=0
second=0
firstg=0
secondg=0
for line in f1:
string = line.split(",")
first=first+1
dict[int(string[0])]=",".join(string[1:])
line=line.replace("
","").rstrip('\n').split(",")
firstg=firstg+float(line[len(line)-1])
for line in f2:
string = line.split(", ")
second=second+1
dict[int(string[0])]=",".join(string[1:])
line=line.replace(" ","").rstrip('\n')
secondg=secondg+float(line[len(line)-1])
for i in sorted(dict.keys()):
f3.write(str(i))
f3.write(dict[i])
f3.close()
f1.close()
f2.close()
print("Total number of students in the class are
",first+second)
print("Total number of students in CINS major are ",first)
print("Total number of students in PBIS major are ",second)
print("Average GPA of students in CINS major is
",round(firstg/first,2))
print("Average GPA of students in PBIS major is
",round(secondg/second,2))
print("Average GPA of whole cass is
",round((firstg+secondg)/(first+second),2))

COMMENT DOWN FOR ANY QUERY
PLEASE GIVE A THUMBS UP
Python Program: Design the logic for and implement a program that merges the two files into...
I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Note: DebugDataOne1.txt and DebugDataOne2.txt do not need to be edited. They are used by the program. import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { public static void main(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1.txt"); // path to file DebugDataOne1.txt in...
Python Programming 4th Edition: Need help writing this program below. I get an error message that says that name is not defined when running the program below. My solution: def main(): filename = "text.txt" contents=f.read() upper_count=0 lower_count=0 digit_count=0 space_count=0 for i in contents: if i.isupper(): upper_count+=1 elif i.islower(): lower_count+=1 elif i.isdigit(): digit_count+=1 elif i.isspace(): space_count+=1 print("Upper case count in the file is",upper_count) print("Lower case count in the file is",lower_count) print("Digit count in the file is",digit_count) print("Space_count in the file is",space_count)...
Program in C Student Data using Structs In this assignment you will create a program (using multiple .c files) to solve the following problem: You have been hired by the university to create a program that will read in input from a .txt file. This input will contain a student name, student id #, their age and their current gpa. You should use the following struct for your student data: struct Student{ char name[50]; int id; float...
Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt, verbs. txt, articles.txt, and prepositions.txt. (HINT: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list...
Python
I'm creating two linked lists from two txt files, merging them,
then printing any duplicates found. My program right now only reads
numbers one after another following a comma. For example
10,20,15,2. How do i change it so it reads numbers one below
another. Like this,
class Node(object):
value = -1
next = None
def __init__(self,item):
self.val = item
self.next = None
def merge_lists(vivendi, activision):
head = tail = Node(0)
...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...
Python 12.10 LAB: Sorting TV Shows (dictionaries and lists)
Write a program that first reads in the name of an input file
and then reads the input file using the file.readlines() method.
The input file contains an unsorted list of number of seasons
followed by the corresponding TV show. Your program should put the
contents of the input file into a dictionary where the number of
seasons are the keys, and a list of TV shows are the values (since...
PYTHON PROGRAMMING: I have this program right now where it allows users to choose from a category(pulling from the file). Then it will print the University or people from that text file. What I want to do next on my code is for users to search for a specific string from that file and it will display both the University and People that have that matching string. It can be the whole word or part of the string from that...
PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 def insert(self, i, data): if self.isEmpty(): self.__head = listNode(data) self.__tail = self.__head elif i <= 0: self.__head = listNode(data, self.__head) elif i >= self.__size: self.__tail.setNext(listNode(data)) self.__tail = self.__tail.getNext() else: current = self.__getIthNode(i - 1) current.setNext(listNode(data,...