Skip to content

jstrzempko/IDCE302_Final-Project

Repository files navigation

Final Project

Due Date: Tuesday, October 6 - 5pm EST

Elise Nycz and Jess Strzempko

Script 1

This script utilizes web scraping techniques to pull the 4-day forecast for a specific longitude and latitude from the National Weather Service website. The script prompts the user to input the latitude and longitude of their interest, and then uses this input to generate the URL for that specific location. When writing the script, the function performed well. The sole error encountered arose from the dynamic nature of the website given that it updates daily. In this instance, instead of relying on the replace function to manually manipulate the forecast in the string output, a for loop was added to identify locations where uppercase and lowercase letters were adjacent, i.e. new words started, to add spaces.

Code like this may be useful when creating a website with forecast projections included on it. Additionally, this web scraping technique could be useful for research purposes. If conducting a research project that required information gathering from social media posts, like twitter, this code could be edited and utilized to obtain the needed information.

Script 2

This script takes a text file and pulls information from it using specific functions. The first code cleans up the data in the text file by removing any extraneous spaces, capitalizing all names and country names, and fixing spelling errors so that the country names can be accurately counted. The strip function removes extraneous spaces, while the split function splits the voters name and the county they voted for by a dash to produce a cleaner and more reader-friendly output.

  1. The first script was easy to write and no errors arose.
  2. The second function reports if a person has already voted. This function is useful to ensure that votes are not being double counted and a more accurate vote count is received. The function uses if/else statements to go through the list and look for repeated names. When a name is seen more than once, a statement will printed indicating this. However, if their name is only seen once, it will not return any output referring to that person and will add their name to an empty list we initially created, voted, at the beginning of the function.
  3. The third function counts the total number of votes for a specific county. The function starts at a counter at zero. The script then uses the same data cleaning code as the first script, removing extraneous spaces, capitalizing the names, and ensuring that county names are spelled correctly. The function uses an if statement where every time the county name used as an argument is seen, the count is incremented by one. A print statement is then given stating how many votes that county has received. For our example, we used Kisumu and had the code return how many votes Kisumu received in total.
  4. The fourth function returns the number of votes for each county, rather than a specific one like in the previous function. An empty dictionary for counts is initially created, and then the function to count the votes is defined using if/else statements. The argument cleans the data as seen in the prior three functions, and then utilizes if/else statements, adding a county to the count list and starting its value at one when its name is first seen. The else statement is then utilized to continue incrementing the vote by one each time its name is seen.

A final output statement is then printed with each county name, the keys in the dictionary, and the number of votes each has, the corresponding values. The last code line of that script calls upon the text file to use as the source file for the code. The last function outputs the county with the highest number of votes and its vote count. An empty dictionary is created to count the votes. If/else statements are then used in the function to count the number of votes based on when the code reads a county's name. When a county's name is seen it increments by one each time. A tuple is then defined to give data pairs of the county names and votes using the items function on the count dictionary. We used the example code from Geeks for Geeks, given in the README, to define the county with the highest vote count. The output is then printed in a statement giving the county name and the number of votes it received.

About

IDCE 302 Python Programming Final Project Team 10

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published