PyBank Main problems to solve:
- Open an CSV file.
-
- Import CSV module
- Need to make sure the file path is correct
- Skip header
- Define variables. As previously practiced. When we need to calculate totals, we need to initiate o values so that we can use loop to add up totals.
- The calculations.
- In this case since there is comparison with the previous month. Need to define the first row. Otherwise the first difference will be the first month value minus 0 (no value exists).
- Need to reset previous_profit_loss after each calculation. I missed this initially and the calculation was wrong.
- Compare change with greatest increase and greatest decrease.
- Use f with tripple string to print the format requested. It's a much easier way than printing line by line.
- Write the report.
- Close file due to the way I opened it.
PyPoll
Main problems to solve. Steps are pretty similar to PyBank.
- Open the CSV file as a dictionary
- Define Variables: Total votes as 0 since we need to add up totals Candidate list as a dictionary Candidate can be pulled by using the key in dictionary instead of row number.
- Using loop:
- Since one line represents one vote for one candidate, loop goes through each line to add a candidate if didn't exist previously, add that candidate and count the respective votes.
- Compare win votes and can votes. Greater one is the win votes.
- Math calculation of percentage votes
- Combine outputs to print.
- Write the report.
- Close the csv file.