Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

This updated version of the Python code has additional functionality to store the

outcomes in a file called "credits.txt". Here is an explanation of each step:

The code starts by declaring the variables progress_count, module_trailer_count,


exclude_count, module_retriever_count and initializes them to 0. It also creates an
empty list called List and opens a file named "credits.txt" in write mode.

The get_credits function is defined, which is the same as before. It takes a


parameter credit_type and asks the user to enter the credits for that type.

The print_outcome function is also the same as before. It takes an outcome


parameter and prints the outcome.

The conditions function is added. It takes the parameters Result, PASS, DEFER, and
FAIL, and appends the outcome and its corresponding credit values to the List. It
also writes the outcome and its credits to the "credits.txt" file.

The code enters the main loop, which repeatedly asks the user for Pass, Defer, and
Fail credits, similar to the previous version.

After getting the credits, the code calculates the total credits and checks if it
is equal to 120. If not, it prints "Total incorrect" and continues to the next
iteration of the loop.

If the Pass credits are equal to 120, the student's outcome is "Progress". The
progress_count is incremented, and the outcome is printed using the print_outcome
function.

If the Pass credits are equal to 100, the student's outcome is "Progress (module
trailer)". The module_trailer_count is incremented, and the outcome is printed.

If the Fail credits are greater than or equal to 80, the student's outcome is
"Exclude". The exclude_count is incremented, and the outcome is printed.

If none of the above conditions are met, the student's outcome is "Module
retriever". The module_retriever_count is incremented, and the outcome is printed.

After determining the outcome, the code asks the user if they want to continue
entering data or exit and showcase the results, similar to the previous version.

If the user chooses to exit and showcase the results, the code prints "Collecting
Data...", breaks out of the loop, and proceeds to the next steps.

The code calculates the total number of outcomes by summing up the count variables.

The code prints a line of underscores to separate the histogram from other output.

The code prints the histogram of the outcomes, similar to the previous version.

Another line of underscores is printed for separation.

The code iterates through the List and prints each element on a new line.

A blank line is printed.

The total number of outcomes is displayed.

Another line of underscores is printed for separation.


The "credits.txt" file is closed.

The "credits.txt" file is opened in read mode and its contents are printed.

That's a step-by-step explanation of the given Python code with the added
functionality of storing outcomes in a file.

You might also like