Home Help & Support Search Tips Options: Case:



   Need A Tutor?    |   Need Homework Help?                                                                             Help and Support     | Join or Cancel

Exam  1     2     3     4     5     6     7    8     9    10     Midterm   1    2     Final Exam  1   2
Graded Program Assignment   
1   2    3    4    5    6    7    8    9           Python Compiler

Computer Programming
Assignment 9
For/While Loops


Create_Name_LIST_FOR_LOOP.py

#========================================================================================================================================
# PROGRAMMER:
# PROGRAM NAME:   Assignment #09 - creating & manipulating arrays / lists of testGradess WHILE LOOP VERSION, using parameters
# DATE WRITTEN:  
#========================================================================================================================================
# PURPOSE:        Organizing the program as functions to create and manipulate testGrades data; it uses WHILE LOOP
#========================================================================================================================================
 
# Function to display instructions for the user
def displayInstructions():
    print();
    print("=" * 110);
    print("You will enter the number of testGrades's to be processed ranging between 0 and 100")
    print("=" * 110);
   
#=================================================================================================================================
# Function to Populate testGrades array with data using a while / loop
def createtestGradesList(count, testGrades, numtestGrades):
   
    print();
    print("=" * 110);
    while (count < numtestGrades):
 
        # check to see if the data type is numeric and the testGrades range is between 0 and 100
        while True:
            try:
                 # add a testGrades to the list using built in append function
                testGrades.append(float(input("Enter testGrades #" + format(count + 1, ">3") + format(" :==> ", ">6s"))));                           
                print("testGrades[" + format(count + 1, "2") + "] = " + format(testGrades[count], ".2f"));
            except ValueError:
                print("You entered the wrong data type! - Please Re-enter correct positive numerical testGrades between 0 and 100");               
                continue;              
            else:
                if (testGrades[count] < 0 or testGrades[count] < 0 or testGrades[count] > 100):
                    print("You entered an incorrect value of ", format(testGrades[count], ".2f") + \
                                                         " Please Re-enter correct positive numerical testGrades between 0 and 100");
                    testGrades.remove(testGrades[count]);     # uses built in function to remove the value with wrong testGrades from the testGrades array/list               
                    continue;
                break;           
        count = count + 1;                      # updates the index
       # end while loop   
    # end createtestGradesArray function
   
#=================================================================================================================================
# Function to Display an Unsorted list of testGrades's
def writeTestGradesList(count, testGrades, numtestGrades):
 
    print();
    while (count < numtestGrades):         # display the testGrades list using the while loop
        outFile.write(format(format("testGrades [", "5s") + format(count + 1, ">2") + \
                     format("] = ", "4s"), "^10s") + format(testGrades[count], "6.2f"));
        outFile.write("\n");
        count = count + 1;  # creates an empty arrayunt + 1;      # update the index lcv variable
        # end while loop
    return count, testGrades           # return the count and testGrades values
    print();
    # end writeTestGradesList function
 
#=================================================================================================================================   
# Search for a specific testGrades in the list and count how many times it occurs.
#
def searchtestGradesList(numtestGrades, targetCount, targettestGrades):   
    count = 0;          # initialize count to search the testGrades array
    targetCount = 0;    # initialize variable to store # of times target value occurs
    print();
   
    # check to see if the data type for the target testGrades is numeric
    # and the target testGrades range is between 0 and 100
    while True:
        try:
            targettestGrades = float(input("What testGrades value are you searching for? "));                           
        except ValueError:
            print("You entered the wrong data type! - Please Re-enter correct positive numerical testGrades between 0 and 100");               
            continue;          
        else:
            if (targettestGrades < 0) or (targettestGrades < 0) or (targettestGrades > 100):
                print("You entered an incorrect value of ", format(targettestGrades, ".2f") + \
                                                     " Please Re-enter correct positive numerical testGrades between 0 and 100");
                continue;
            break;    
      
    while(count < numtestGrades):                      # Loop to search or navigate through the testGrades array/list for the target testGrades
 
        if (targettestGrades == testGrades[count]):       # if/selection statement to compare target testGrades to values in the list.
            targetCount = targetCount + 1;  # stores each occurence inside the targetCount
            # end if       
        count = count + 1;                  # update the index lcv variable
        # end while loop
    return targetCount, targettestGrades;          # return the count and testGrades values
    #end searchtestGradesList function
#=================================================================================================================================
# Function to Display a specific testGrades in the list and count how many times it occurs.
def writeSearchResults():
 
    print();
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("The target testGrades " + "\"" + format(targettestGrades, ".2f") + "\"" + ", occur(s) " +   
                                                    format(targetCount, "2") + " time(s) in the testGrades List.");
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("\n");
    outFile.write("=" * 110);
    # end writeSearchResults function
   
#=================================================================================================================================
# Function to determine the minimum or lowest testGrades
def determineMinimumtestGrades(testGrades):
    # A built in function "min()" is used
    print();
    outFile.write("\n");
    minimumtestGrades = min(testGrades); # using a built in function called min to determine the minimum testGrades in the list
    outFile.write("The smallest testGrades =  " + format(minimumtestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("\n");
    outFile.write("=" * 110);
    print();
    # end determineMinimumtestGrades function
   
#=================================================================================================================================
# Function to determine the minimum or lowest testGrades
def determineMaximumtestGrades(testGrades):
    # A built in function "min()" is used
    print();
    outFile.write("\n");
    maximumtestGrades = max(testGrades); # using a built in function called max to determine the minimum testGrades in the list
    outFile.write("The largest testGrades = " + format(maximumtestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    print();
    # end determineMaximumtestGrades function
   
#=================================================================================================================================
def calculateAveragetestGrades(testGrades):
    # use built in functions sum and len to calculate average
    averagetestGrades = sum(testGrades) / len(testGrades);
    print();
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("The average testGrades = " + format(averagetestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    # end calculateAveragetestGrades function
#=================================================================================================================================
 
#Function to Display the Programmer information
def writeProgrammerInformation():
    print();
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("Assignment #09 Creating & Manipulating ARRAYS/LISTS [Executed & tested by Nicole Provost-Tooley.]");
    outFile.write("\n");
    outFile.write("=" * 110);
    # End writeProgrammerInformation function
#=================================================================================================================================
# Function to create a file to write the result to an external file in note pad
# open or create the external file
def createOutputFile(outFile):
    outFileName = input("Please type the name of the file where you wish to write the output "\
                        "\"end the file with .txt\" --->");
    outFile = open(outFileName, "w");
    return outFile;
    # end createOutFile function
#=================================================================================================================================
# Main Program
#=================================================================================================================================
# initialize variables and array  
count = 0; # initialize lcv / index of the the testGrades array / list
outFile = [];
testGrades = [];  # creates an empty array / list
numtestGrades = int(input("Enter the number of testGrades's you will enter into the array / list today:\n"));
            
targetCount = 0;                        # Initialize variable to return number of occurences of target value                     
targettestGrades = 0.00;                       # Initialize Variable to return actual target testGrades
displayInstructions();                  # Call function to display direction for user.
outFile = createOutputFile(outFile);   # call function to open the output file where all the output will be written
createtestGradesList(count, testGrades, numtestGrades);      # Call function to populates the array with Actual testGrades data
 
# Heading for unsorted list
print();
outFile.write("=" * 110);
outFile.write("\n");
outFile.write(format("UNSORTED TEST GRADES LIST", "^30"));
outFile.write("=" * 110);
outFile.write("\n");
outFile.write("\n");
outFile.write("=" * 110);
outFile.write("\n");
 
writeTestGradesList(count, testGrades, numtestGrades);     # Call function to Displays a list of testGradesS
 
# Heading for sorted list
print();
outFile.write("=" * 110);
outFile.write("\n");
outFile.write(format("SORTED TEST GRADES LIST", "^30"));
outFile.write("=" * 110);
outFile.write("\n");
outFile.write("\n");
outFile.write("=" * 110);
outFile.write("\n");
 
testGrades.sort();                             # Call built in sort function
 
writeTestGradesList(count, testGrades, numtestGrades);     # Call function to Displays a list of testGradesS
targetCount, targettestGrades = searchtestGradesList(numtestGrades,targetCount, targettestGrades);# Call function to search for a specific testGrades
writeSearchResults();                 # Call function to display results of searching for a specific testGrades
determineMinimumtestGrades(testGrades);               # Call function to determine and display smallest testGrades in list
determineMaximumtestGrades(testGrades);               # Call function to determine and display largest testGrades in list
calculateAveragetestGrades(testGrades);               # Call function to calculate the average testGrades
writeProgrammerInformation();         # Call function to display Programmer's information
outFile.close();
#=================================================================================================================================
# End Program

#========================================================================================================================================
# PROGRAMMER:    
# PROGRAM NAME:   Assignment #09 FOR LOOP creating and
#                 manipulating arrays / lists of GPAs using parameters
# DATE WRITTEN:   07/14/2019
#========================================================================================================================================
# PURPOSE:        Organizing the program as functions to create and manipulate gpa data, uses FOR LOOP
#========================================================================================================================================
# Function to display user instructions
def displayInstructions():
    print();
    print("=" * 110);
    print("Please enter the number of gpa's to be processed that is within the range of 1.00 and 4.00");
    print("=" * 110);
#========================================================================================================================================
# Function to populate gpa array with data using a FOR loop
def createGpaList(count, gpa, numGpa):
 
    print(); # displays an invisible line
    print("=" * 110); # displays a separation line of 110 double dashes
    for count in range(0, numGpa, 1):
 
        # check to see if data type is numeric & if gpa range is between 1.00 and 4.00
        while True:
            try:
                # add a gps to the list using built in append function
                gpa.append(float(input("Please enter GPA #" + format(count + 1, ">3") + format(" :==> ", ">6s"))));
                print("GPA[" + format(count + 1, "2") + "] = " + format(gpa[count], ".2f"));
            except ValueError:
                print("You entered the wrong data type! - Please Re-enter correct positive numerical GPA between 1.00 and 4.00");
                continue;
            else:
                if (gpa[count] < 0 or gpa[count] < 1.00 or gpa[count] > 4.00):
                    print("You entered an incorrect value of ", format(gpa[count], ".2f") + \
                                                         " Please Re-enter correct positive numerical GPA between 1.00 and 4.00");
 
                    gpa.remove(gpa[count]);   # uses the built in function to remove the value with wrong GPA value from GPA array/list
                    continue;
                break;
        count = count + 1;                    # updates the index
        # end FOR LOOP
     # end createGpaArray function
#========================================================================================================================================
# Function to display an UNSORTED LIST of Gpa's
def displayGpaList (count, gpa, numGpa):
 
    print();
    print("=" * 110);
    for count in range (0, numGpa, 1):
        print(format(format("GPA [", "5s") + format(count + 1, ">2") + \
                     format("] = ", "4s"), "^10s") + format(gpa[count], "6.2f"));
        # END FOR LOOP
    return count, gpa
    print("=" * 110);
    print ();
    # end displayGpaList function
#========================================================================================================================================
# Search for a specific GPA in array / list and count how many times it occurs
def searchGpaList(numGpa, targetCount, targetGpa):
    count = 0;          # initialize count to search the gpa array
    targetCount = 0;    # initialize variable to store # of times target value occurs
    print();
 
    # check to see if the data type for the target gpa is numeric
    # and the target GPA range is between 1.00 and 4.00
    while True:
        try:
            targetGpa = float(input("What GPA value are you searching for? "));
        except ValueError:
            print("You entered the wrong data type! - Please Re-enter correct positive numerical GPA between 1.00 and 4.00");
            continue;
        else:
            if (targetGpa < 0) or (targetGpa < 1.00) or (targetGpa > 4.00):
                print("You entered an incorrect value of ", format(targetGpa, ".2f") + \
                                                     " Please Re-enter correct positive numerical GPA between 1.00 and 4.00");
                continue;
            break;
 
    for count in range(0, numGpa, 1):                # Loop to search or navigate through the GPA array/list for the target GPA
                   
         if (targetGpa == gpa[count]):          # if/selection statement to compare target gpa to value in the list
             targetCount = targetCount + 1;     # stores each occurence inside the targetCount
             # end if
         # end FOR LOOP
    return targetCount, targetGpa;              # return the count and gpa values
    # end searchGpaList function
#========================================================================================================================================
# Function to display a specific GPA in the list and count how many times it occurs
def displaySearchResults():
    print();
    print("=" * 110);
    print("The target GPA " + "\"" + format(targetGpa, ".2f") + "\"" + ", occur(s) " +
                                                    format(targetCount, "2") + " time(s) in the GPA List.");
    print("=" * 110);
    # end displaySearchResults function
#========================================================================================================================================
# Function to determine the minimum (lowest GPA)
def determineMinimumGpa(gpa):
    # A built in function "min()" is used
    print();
    print("=" * 110);
    minimumGpa = min(gpa); # using a built in function called the min to determine the minimum GPA in the list
    print("The smallest gpa = ", format(minimumGpa, ".2f"));
    print("=" * 110);
    print();
    # end determineMinimumGpa function          
#========================================================================================================================================
# Function to determine the maximum (highest GPA)
def determineMaximumGpa(gpa):
    # A built in function "max()" is used
    print();
    print("=" * 110);
    maximumGpa = max(gpa); # using a built in function called max to determine the maximum gpa in the list
    print("The largest gpa = ", format(maximumGpa, ".2f"));
    print("=" * 110);
    print();
    # end determineMaximumGpa function
#========================================================================================================================================
def calculateAverageGpa(gpa):
    # use built in functions sum len to calculate average
    averageGpa = sum(gpa) / len(gpa);
    print();
    print("=" * 110);
    print("The average gpa = ", format(averageGpa, ".2f"));
    print("=" * 110);
    # end calculateAverageGpa function
#========================================================================================================================================
# function to display programmer information
def displayProgrammerInformation():
    print();
    print("=" * 110);
    print("Assignment #09 Creating & Manipulating ARRAYS / LISTS [Executed & Tested by Robert Zink]");
    print("=" * 110);
    # End displayProgrammerInformation function
#========================================================================================================================================
# Main Program
#========================================================================================================================================                  
# initialize variables and array
count = 0; # initialize lcv / index of the gpa array/list
gpa = [];  # creates an empty array / list
numGpa = int(input("Please enter the number of gpa's you will enter into the array / list today:\n"));
 
targetCount = 0;                               # initialize variable to return number of occurences of target value
targetGpa = 0.00;                              # initialize variable to return actual target Gpa
displayInstructions();                         # Call function to display direction of user
createGpaList(count, gpa, numGpa);             # Call function populates array with ACTUAL GPA data
 
# heading for unsorted list
print();
print("=" * 110);
print(format("UNSORTED GPA LIST", "^30"));
print("=" * 110);
 
displayGpaList(count, gpa, numGpa);            # Call function displays a list of GPAs
 
# headed for sorted list
print();
print("=" * 110);
print(format("SORTED GPA LIST", "^30"));
print("=" * 110);
#========================================================================================================================================
gpa.sort();                                   # Call built in sort function
 
displayGpaList(count, gpa, numGpa);           # Call function to display a list of GPAs
targetCount, targetGpa = searchGpaList(numGpa, targetCount, targetGpa); # Call function to search for a specific GP
displaySearchResults();                       # Call function to display results of searching for a specific GPA
determineMinimumGpa(gpa);                     # Call function to determine and display smallest GPA in list
determineMaximumGpa(gpa);                     # Call function to determine and display largest gpa in list
calculateAverageGpa(gpa);                     # Call function to calculate the average GPA
displayProgrammerInformation();               # Call function to display Programmer's Information
#========================================================================================================================================
# END PROGRAM

#=================================================================================================================================
# Programmer  :
# Program Name: Enter Assignment # here - Creating and manipulating a list of gpas (WHILE LOOP Version)
#               Using Parameters.
# DATE WRITTEN: 7/15/2019
# PURPOSE:      Organizing the program as functions to create and manipulate gpa data
#=================================================================================================================================
# Function to display instructions for the user
def displayInstructions():
    print();
    print("=" * 110);
    print("You will enter the number of gpa's to be processed ranging between 1.00 and 4.00")
    print("=" * 110);
   
#=================================================================================================================================
# Function to Populate gpa array with data using a while / loop
def createGpaList(count, gpa, numGpa):
   
    print();
    print("=" * 110);
    while (count < numGpa):
 
        # check to see if the data type is numeric and the GPA range is between 1.00 and 4.00
        while True:
            try:
                 # add a gpa to the list using built in append function
                gpa.append(float(input("Enter GPA #" + format(count + 1, ">3") + format(" :==> ", ">6s"))));                           
                print("GPA[" + format(count + 1, "2") + "] = " + format(gpa[count], ".2f"));
            except ValueError:
                print("You entered the wrong data type! - Please Re-enter correct positive numerical GPA between 1.00 and 4.00");               
                continue;              
            else:
                if (gpa[count] < 0 or gpa[count] < 1.00 or gpa[count] > 4.00):
                    print("You entered an incorrect value of ", format(gpa[count], ".2f") + \
                                                         " Please Re-enter correct positive numerical GPA between 1.00 and 4.00");
                    gpa.remove(gpa[count]);     # uses built in function to remove the value with wrong GPA from the GPA array/list               
                    continue;
                break;           
        count = count + 1;                      # updates the index
       # end while loop   
    # end createGpaArray function
 
#=================================================================================================================================
# Function to Display an Unsorted list of Gpa's
def displayGpaList(count, gpa, numGpa):
 
    print();
    print("=" * 110);
    while (count < numGpa):         # display the GPA list using the while loop
        print(format(format("GPA [", "5s") + format(count + 1, ">2") + \
                     format("] = ", "4s"), "^10s") + format(gpa[count], "6.2f"));
        count = count + 1;  # creates an empty arrayunt + 1;      # update the index lcv variable
        # end while loop
    return count, gpa           # return the count and gpa values
    print("=" * 110);
    print();
    # end displayGpaList function
 
#=================================================================================================================================   
# Search for a specific GPA in the list and count how many times it occurs.
#
def searchGpaList(numGpa, targetCount, targetGpa):   
    count = 0;          # initialize count to search the gpa array
    targetCount = 0;    # initialize variable to store # of times target value occurs
    print();
   
    # check to see if the data type for the target gpa is numeric
    # and the target GPA range is between 1.00 and 4.00
    while True:
        try:
            targetGpa = float(input("What GPA value are you searching for? "));                           
        except ValueError:
            print("You entered the wrong data type! - Please Re-enter correct positive numerical GPA between 1.00 and 4.00");               
            continue;          
        else:
            if (targetGpa < 0) or (targetGpa < 1.00) or (targetGpa > 4.00):
                print("You entered an incorrect value of ", format(targetGpa, ".2f") + \
                                                     " Please Re-enter correct positive numerical GPA between 1.00 and 4.00");
                continue;
            break;    
      
    while(count < numGpa):                      # Loop to search or navigate through the gpa array/list for the target gpa
 
        if (targetGpa == gpa[count]):       # if/selection statement to compare target gpa to values in the list.
            targetCount = targetCount + 1;  # stores each occurence inside the targetCount
            # end if       
        count = count + 1;                  # update the index lcv variable
        # end while loop
    return targetCount, targetGpa;          # return the count and gpa values
    #end searchGpaList function
       
#=================================================================================================================================
# Function to Display a specific GPA in the list and count how many times it occurs.
def displaySearchResults():
 
    print();
    print("=" * 110);
    print("The target GPA " + "\"" + format(targetGpa, ".2f") + "\"" + ", occur(s) " +   
                                                    format(targetCount, "2") + " time(s) in the GPA List.");
    print("=" * 110);
   
    # end displaySearchResults function
   
#=================================================================================================================================
# Function to determine the minimum or lowest GPA
def determineMinimumGpa(gpa):
    # A built in function "min()" is used
    print();
    print("=" * 110);
    minimumGpa = min(gpa); # using a built in function called min to determine the minimum gpa in the list
    print("The smallest gpa =  " + format(minimumGpa, ".2f"));
    print("=" * 110);
    print();
    # end determineMinimumGpa function
   
#=================================================================================================================================
# Function to determine the minimum or lowest GPA
def determineMaximumGpa(gpa):
    # A built in function "min()" is used
    print();
    print("=" * 110);
    maximumGpa = max(gpa); # using a built in function called max to determine the minimum gpa in the list
    print("The largest gpa = " + format(maximumGpa, ".2f"));
    print("=" * 110);
    print();
    # end determineMaximumGpa function
   
#=================================================================================================================================
def calculateAverageGpa(gpa):
    # use built in functions sum and len to calculate average
    averageGpa = sum(gpa) / len(gpa);
    print();
    print("=" * 110);   
    print("The average gpa = " + format(averageGpa, ".2f"));
    print("=" * 110);
    # end calculateAverageGpa function
#=================================================================================================================================
 
#Function to Display the Programmer information
def displayProgrammerInformation():
    print();
    print("=" * 110);
    print("Assignment #09 Creating & Manipulating ARRAYS/LISTS [Executed & tested by Robert Zink.]");
    print("=" * 110);
    # End displayProgrammerInformation function
       
#=================================================================================================================================
# Main Program
#=================================================================================================================================
# initialize variables and array  
count = 0; # initialize lcv / index of the the gpa array / list
gpa = [];  # creates an empty array / list
numGpa = int(input("Enter the number of gpa's you will enter into the array / list today:\n"));
            
targetCount = 0;                        # Initialize variable to return number of occurences of target value                     
targetGpa = 0.00;                       # Initialize Variable to return actual target Gpa
displayInstructions();                  # Call function to display direction for user.
createGpaList(count, gpa, numGpa);      # Call function to populates the array with Actual GPA data
 
# Heading for unsorted list
print();
print("=" * 110);
print(format("UNSORTED GPA LIST", "^30"));
print("=" * 110);
 
displayGpaList(count, gpa, numGpa);     # Call function to Displays a list of GPAS
 
# Heading for sorted list
print();
print("=" * 110);
print(format("SORTED GPA LIST", "^30"));
print("=" * 110);
 
gpa.sort();                             # Call built in sort function
 
displayGpaList(count, gpa, numGpa);     # Call function to Displays a list of GPAS
targetCount, targetGpa = searchGpaList(numGpa,targetCount, targetGpa);# Call function to search for a specific GPA
displaySearchResults();                 # Call function to display results of searching for a specific GPA
determineMinimumGpa(gpa);               # Call function to determine and display smallest gpa in list
determineMaximumGpa(gpa);               # Call function to determine and display largest gpa in list
calculateAverageGpa(gpa);               # Call function to calculate the average gpa
displayProgrammerInformation();         # Call function to display Programmer's information
#=================================================================================================================================
# End Program

#========================================================================================================================================
# PROGRAMMER:     Robert Zink
# PROGRAM NAME:   Assignment #09 FOR LOOP creating and data files
#                 manipulating arrays / lists of testGradess using parameters
# DATE WRITTEN:   07/14/2019
#========================================================================================================================================
# PURPOSE:        Organizing the program as functions to create and manipulate testGrades data, uses FOR LOOP
#========================================================================================================================================
# Function to display user instructions
def displayInstructions():
    print();
    print("=" * 110);
    print("Please enter the number of testGrades's to be processed that is within the range of 0 and 100");
    print("=" * 110);
#========================================================================================================================================
# Function to populate testGrades array with data using a FOR loop
def createtestGradesList(count, testGrades, numtestGrades):
 
    print(); # displays an invisible line
    print("=" * 110); # displays a separation line of 110 double dashes
    for count in range(0, numtestGrades, 1):
 
        # check to see if data type is numeric & if testGrades range is between 0 and 100
        while True:
            try:
                # add a gps to the list using built in append function
                testGrades.append(float(input("Please enter testGrades #" + format(count + 1, ">3") + format(" :==> ", ">6s"))));
                print("testGrades[" + format(count + 1, "2") + "] = " + format(testGrades[count], ".2f"));
            except ValueError:
                print("You entered the wrong data type! - Please Re-enter correct positive numerical testGrades between 1.00 and 4.00");
                continue;
            else:
                if (testGrades[count] < 0 or testGrades[count] < 0 or testGrades[count] > 100):
                    print("You entered an incorrect value of ", format(testGrades[count], ".2f") + \
                                                         " Please Re-enter correct positive numerical testGrades between 0 and 100");
 
                    testGrades.remove(testGrades[count]);   # uses the built in function to remove the value with wrong testGrades value from testGrades array/list
                    continue;
                break;
        count = count + 1;                    # updates the index
        # end FOR LOOP
     # end createtestGradesArray function
#========================================================================================================================================
# Function to display an UNSORTED LIST of testGrades's
def writeTestGradesList (count, testGrades, numtestGrades):
 
    print();
    print("=" * 110);
    for count in range (0, numtestGrades, 1):
        outFile.write(format(format("testGrades [", "5s") + format(count + 1, ">2") + \
                     format("] = ", "4s"), "^10s") + format(testGrades[count], "6.2f"));
        outFile.write("\n");
        # END FOR LOOP
    return count, testGrades
    print("=" * 110);
    print ();
    # end writeTestGradesList function
#========================================================================================================================================
# Search for a specific testGrades in array / list and count how many times it occurs
def searchtestGradesList(numtestGrades, targetCount, targettestGrades):
    count = 0;          # initialize count to search the testGrades array
    targetCount = 0;    # initialize variable to store # of times target value occurs
    print();
 
    # check to see if the data type for the target testGrades is numeric
    # and the target testGrades range is between 1.00 and 4.00
    while True:
        try:
            targettestGrades = float(input("What testGrades value are you searching for? "));
        except ValueError:
            print("You entered the wrong data type! - Please Re-enter correct positive numerical testGrades between 0 and 100");
            continue;
        else:
            if (targettestGrades < 0) or (targettestGrades < 0) or (targettestGrades > 100):
                print("You entered an incorrect value of ", format(targettestGrades, ".2f") + \
                                                     " Please Re-enter correct positive numerical testGrades between 0 and 100");
                continue;
            break;
 
    for count in range(0, numtestGrades, 1):                # Loop to search or navigate through the testGrades array/list for the target testGrades
                   
         if (targettestGrades == testGrades[count]):          # if/selection statement to compare target testGrades to value in the list
             targetCount = targetCount + 1;     # stores each occurence inside the targetCount
             # end if
         # end FOR LOOP
    return targetCount, targettestGrades;              # return the count and testGrades values
    # end searchtestGradesList function
#========================================================================================================================================
# Function to display a specific testGrades in the list and count how many times it occurs
def writeSearchResults():
   
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n"); # displays a blank line
    outFile.write("The target testGrades " + "\"" + format(targettestGrades, ".2f") + "\"" + ", occur(s) " +
                                                    format(targetCount, "2") + " time(s) in the testGrades List.");
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("=" * 110);
    # end writeSearchResults function
#========================================================================================================================================
# Function to determine the minimum (lowest testGrades)
def determineMinimumtestGrades(testGrades):
    # A built in function "min()" is used
    print();
    outFile.write("\n");
    minimumtestGrades = min(testGrades); # using a built in function called the min to determine the minimum testGrades in the list
    outFile.write("The smallest testGrades =  " + format(minimumtestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("=" * 110);
    print();
    # end determineMinimumtestGrades function          
#========================================================================================================================================
# Function to determine the maximum (highest testGrades)
def determineMaximumtestGrades(testGrades):
    # A built in function "max()" is used
    outFile.write("\n");
    maximumtestGrades = max(testGrades); # using a built in function called max to determine the maximum testGrades in the list
    outFile.write("The largest testGrades = " + format(maximumtestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    print();
    # end determineMaximumtestGrades function
#========================================================================================================================================
def calculateAveragetestGrades(testGrades):
    # use built in functions sum len to calculate average
    averagetestGrades = sum(testGrades) / len(testGrades);
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("The average testGrades = " + format(averagetestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    # end calculateAveragetestGrades function
#========================================================================================================================================
# function to display programmer information
def writeProgrammerInformation():
    print();
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("Assignment #09 Creating & Manipulating ARRAYS/LISTS [Executed & tested by Robert Zink.]");
    outFile.write("\n");
    outFile.write("=" * 110);
    # writeProgrammerInformation function
#=====================================================================================================================
# Function to create a file to write the result to an external file in note pad
# open or create the external file
def createOutputFile(outFile):
    outFileName = input("Please type the name of the file where you wish to write the output "\
                        "\"end the file with .txt\" --->");
    outFile = open(outFileName, "w");
    return outFile;
    # end createOutFile function
#========================================================================================================================================
# Main Program
#========================================================================================================================================                  
# initialize variables and array
count = 0; # initialize lcv / index of the testGrades array/list
outFile = [];
testGrades = [];  # creates an empty array / list
numtestGrades = int(input("Please enter the number of testGrades's you will enter into the array / list today:\n"));
 
targetCount = 0;                               # initialize variable to return number of occurences of target value
targettestGrades = 0.00;                              # initialize variable to return actual target testGrades
displayInstructions();                         # Call function to display direction of user
outFile = createOutputFile(outFile);   # call function to open the output file where all the output will be written
createtestGradesList(count, testGrades, numtestGrades);             # Call function populates array with ACTUAL testGrades data
 
# heading for unsorted list
print();
outFile.write("\n");
outFile.write("=" * 110);
outFile.write("\n");
outFile.write(format("UNSORTED TEST GRADES LIST", "^30"));
outFile.write("=" * 110);
outFile.write("\n"); # displays a blank line
outFile.write("=" * 110);
outFile.write("\n");
 
writeTestGradesList(count, testGrades, numtestGrades);            # Call function displays a list of testGradess
 
# headed for sorted list
print();
outFile.write("=" * 110);
outFile.write("\n");
outFile.write(format("SORTED TEST GRADES LIST", "^30"));
outFile.write("=" * 110);
outFile.write("\n"); # displays a blank line
outFile.write("=" * 110);
outFile.write("\n");
#========================================================================================================================================
testGrades.sort();                                   # Call built in sort function
 
writeTestGradesList(count, testGrades, numtestGrades);           # Call function to display a list of testGradess
targetCount, targettestGrades = searchtestGradesList(numtestGrades, targetCount, targettestGrades); # Call function to search for a specific GP
writeSearchResults();                       # Call function to display results of searching for a specific testGrades
determineMinimumtestGrades(testGrades);                     # Call function to determine and display smallest testGrades in list
determineMaximumtestGrades(testGrades);                     # Call function to determine and display largest testGrades in list
calculateAveragetestGrades(testGrades);                     # Call function to calculate the average testGrades
writeProgrammerInformation();               # Call function to display Programmer's Information
outFile.close();
#========================================================================================================================================
# END PROGRAM

#=================================================================================================================================
# Programmer  : Rober Zink
# Program Name: Enter Assignment # here - Creating and manipulating a list of testGradess (WHILE LOOP Version)
#               Using Parameters.
# DATE WRITTEN: 7/15/2019
# PURPOSE:      Organizing the program as functions to create and manipulate testGrades data
#=================================================================================================================================
# Function to display instructions for the user
def displayInstructions():
    print();
    print("=" * 110);
    print("You will enter the number of testGrades's to be processed ranging between 0 and 100")
    print("=" * 110);
   
#=================================================================================================================================
# Function to Populate testGrades array with data using a while / loop
def createtestGradesList(count, testGrades, numtestGrades):
   
    print();
    print("=" * 110);
    while (count < numtestGrades):
 
        # check to see if the data type is numeric and the testGrades range is between 0 and 100
        while True:
            try:
                 # add a testGrades to the list using built in append function
                testGrades.append(float(input("Enter testGrades #" + format(count + 1, ">3") + format(" :==> ", ">6s"))));                           
                print("testGrades[" + format(count + 1, "2") + "] = " + format(testGrades[count], ".2f"));
            except ValueError:
                print("You entered the wrong data type! - Please Re-enter correct positive numerical testGrades between 0 and 100");               
                continue;              
            else:
                if (testGrades[count] < 0 or testGrades[count] < 0 or testGrades[count] > 100):
                    print("You entered an incorrect value of ", format(testGrades[count], ".2f") + \
                                                         " Please Re-enter correct positive numerical testGrades between 0 and 100");
                    testGrades.remove(testGrades[count]);     # uses built in function to remove the value with wrong testGrades from the testGrades array/list               
                    continue;
                break;           
        count = count + 1;                      # updates the index
       # end while loop   
    # end createtestGradesArray function
   
#=================================================================================================================================
# Function to Display an Unsorted list of testGrades's
def writeTestGradesList(count, testGrades, numtestGrades):
 
    print();
    while (count < numtestGrades):         # display the testGrades list using the while loop
        outFile.write(format(format("testGrades [", "5s") + format(count + 1, ">2") + \
                     format("] = ", "4s"), "^10s") + format(testGrades[count], "6.2f"));
        outFile.write("\n");
        count = count + 1;  # creates an empty arrayunt + 1;      # update the index lcv variable
        # end while loop
    return count, testGrades           # return the count and testGrades values
    print();
    # end writeTestGradesList function
 
#=================================================================================================================================   
# Search for a specific testGrades in the list and count how many times it occurs.
#
def searchtestGradesList(numtestGrades, targetCount, targettestGrades):   
    count = 0;          # initialize count to search the testGrades array
    targetCount = 0;    # initialize variable to store # of times target value occurs
    print();
   
    # check to see if the data type for the target testGrades is numeric
    # and the target testGrades range is between 0 and 100
    while True:
        try:
            targettestGrades = float(input("What testGrades value are you searching for? "));                           
        except ValueError:
            print("You entered the wrong data type! - Please Re-enter correct positive numerical testGrades between 0 and 100");               
            continue;          
        else:
            if (targettestGrades < 0) or (targettestGrades < 0) or (targettestGrades > 100):
                print("You entered an incorrect value of ", format(targettestGrades, ".2f") + \
                                                     " Please Re-enter correct positive numerical testGrades between 0 and 100");
                continue;
            break;    
      
    while(count < numtestGrades):                      # Loop to search or navigate through the testGrades array/list for the target testGrades
 
        if (targettestGrades == testGrades[count]):       # if/selection statement to compare target testGrades to values in the list.
            targetCount = targetCount + 1;  # stores each occurence inside the targetCount
            # end if       
        count = count + 1;                  # update the index lcv variable
        # end while loop
    return targetCount, targettestGrades;          # return the count and testGrades values
    #end searchtestGradesList function
       
#=================================================================================================================================
# Function to Display a specific testGrades in the list and count how many times it occurs.
def writeSearchResults():
 
    print();
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n"); # displays a blank line
    outFile.write("The target testGrades " + "\"" + format(targettestGrades, ".2f") + "\"" + ", occur(s) " +   
                                                    format(targetCount, "2") + " time(s) in the testGrades List.");
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("=" * 110);
    # end writeSearchResults function
   
#=================================================================================================================================
# Function to determine the minimum or lowest testGrades
def determineMinimumtestGrades(testGrades):
    # A built in function "min()" is used
    print();
    outFile.write("\n");
    minimumtestGrades = min(testGrades); # using a built in function called min to determine the minimum testGrades in the list
    outFile.write("The smallest testGrades =  " + format(minimumtestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("=" * 110);
    print();
    # end determineMinimumtestGrades function
   
#=================================================================================================================================
# Function to determine the minimum or lowest testGrades
def determineMaximumtestGrades(testGrades):
    # A built in function "min()" is used
    print();
    outFile.write("\n");
    maximumtestGrades = max(testGrades); # using a built in function called max to determine the minimum testGrades in the list
    outFile.write("The largest testGrades = " + format(maximumtestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    print();
    # end determineMaximumtestGrades function
   
#=================================================================================================================================
def calculateAveragetestGrades(testGrades):
    # use built in functions sum and len to calculate average
    averagetestGrades = sum(testGrades) / len(testGrades);
    print();
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("The average testGrades = " + format(averagetestGrades, ".2f"));
    outFile.write("\n");
    outFile.write("=" * 110);
    # end calculateAveragetestGrades function
#=================================================================================================================================
 
#Function to Display the Programmer information
def writeProgrammerInformation():
    print();
    outFile.write("\n");
    outFile.write("=" * 110);
    outFile.write("\n");
    outFile.write("Assignment #09 Creating & Manipulating ARRAYS/LISTS [Executed & tested by Robert Zink.]");
    outFile.write("\n");
    outFile.write("=" * 110);
    # End writeProgrammerInformation function
#=================================================================================================================================
# Function to create a file to write the result to an external file in note pad
# open or create the external file
def createOutputFile(outFile):
    outFileName = input("Please type the name of the file where you wish to write the output "\
                        "\"end the file with .txt\" --->");
    outFile = open(outFileName, "w");
    return outFile;
    # end createOutFile function
#=================================================================================================================================
# Main Program
#=================================================================================================================================
# initialize variables and array  
count = 0; # initialize lcv / index of the the testGrades array / list
outFile = [];
testGrades = [];  # creates an empty array / list
numtestGrades = int(input("Enter the number of testGrades's you will enter into the array / list today:\n"));
            
targetCount = 0;                        # Initialize variable to return number of occurences of target value                     
targettestGrades = 0.00;                       # Initialize Variable to return actual target testGrades
displayInstructions();                  # Call function to display direction for user.
outFile = createOutputFile(outFile);   # call function to open the output file where all the output will be written
createtestGradesList(count, testGrades, numtestGrades);      # Call function to populates the array with Actual testGrades data
 
# Heading for unsorted list
print();
outFile.write("=" * 110);
outFile.write("\n");
outFile.write(format("UNSORTED TEST GRADES LIST", "^30"));
outFile.write("=" * 110);
outFile.write("\n"); # displays a blank line
outFile.write("=" * 110);
outFile.write("\n");
 
writeTestGradesList(count, testGrades, numtestGrades);     # Call function to Displays a list of testGradesS
 
# Heading for sorted list
print();
outFile.write("=" * 110);
outFile.write("\n");
outFile.write(format("SORTED TEST GRADES LIST", "^30"));
outFile.write("=" * 110);
outFile.write("\n"); # displays a blank line
outFile.write("=" * 110);
outFile.write("\n");
 
testGrades.sort();                             # Call built in sort function
 
writeTestGradesList(count, testGrades, numtestGrades);     # Call function to Displays a list of testGradesS
targetCount, targettestGrades = searchtestGradesList(numtestGrades,targetCount, targettestGrades);# Call function to search for a specific testGrades
writeSearchResults();                 # Call function to display results of searching for a specific testGrades
determineMinimumtestGrades(testGrades);               # Call function to determine and display smallest testGrades in list
determineMaximumtestGrades(testGrades);               # Call function to determine and display largest testGrades in list
calculateAveragetestGrades(testGrades);               # Call function to calculate the average testGrades
writeProgrammerInformation();         # Call function to display Programmer's information
outFile.close();
#=================================================================================================================================
# End Program


Exam  1     2     3     4     5     6     7    8     9    10     Midterm   1    2     Final Exam  1   2
Graded Program Assignment   
1   2    3    4    5    6    7    8    9           Python Compiler


Home
Accounting & Finance Business
Computer Science General Studies Math Sciences
Civics Exam
Everything Else
Help & Support
Join/Cancel
Contact Us
 Login / Log Out