diff --git a/.gitignore b/.gitignore index 6387f56..48406a8 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ screenshots/ # Notes file notes.txt + +# Batch file +*.bat diff --git a/electoral_votes_simulator_october_2024.py b/electoral_votes_simulator_october_2024.py deleted file mode 100644 index ac0bdba..0000000 --- a/electoral_votes_simulator_october_2024.py +++ /dev/null @@ -1,174 +0,0 @@ -# Thanks to Stiched aka discord user id 220689361627250688 for implementing a lot of the code to this project as well as additional discord members for their help and support. -# Initialize vote counts and electoral votes -total_votes = 0 -candidate_1_electoral_votes = 0 -candidate_2_electoral_votes = 0 -candidate_1_popular_votes = 0 # New variable for Candidate 1 popular votes -candidate_2_popular_votes = 0 # New variable for Candidate 2 popular votes - -# Electoral Locations and their Electoral Votes -electoral_votes_locations = { - "Alabama": 9, - "Alaska": 3, - "Arizona": 11, - "Arkansas": 6, - "California": 54, # Adjusted for 2020 Census - "Colorado": 10, - "Connecticut": 7, - "Delaware": 3, - "District of Columbia": 3, # Washington, D.C. - "Florida": 30, - "Georgia": 16, - "Hawaii": 4, - "Idaho": 4, - "Illinois": 19, - "Indiana": 11, - "Iowa": 6, - "Kansas": 6, - "Kentucky": 8, - "Louisiana": 8, - "Maine": 4, - "Maryland": 10, - "Massachusetts": 11, - "Michigan": 15, - "Minnesota": 10, - "Mississippi": 6, - "Missouri": 10, - "Montana": 3, - "Nebraska": 5, - "Nevada": 6, - "New Hampshire": 4, - "New Jersey": 14, - "New Mexico": 5, - "New York": 28, - "North Carolina": 16, - "North Dakota": 3, - "Ohio": 17, - "Oklahoma": 7, - "Oregon": 7, - "Pennsylvania": 19, - "Rhode Island": 4, - "South Carolina": 9, - "South Dakota": 3, - "Tennessee": 11, - "Texas": 40, - "Utah": 6, - "Vermont": 3, - "Virginia": 13, - "Washington": 12, - "West Virginia": 4, - "Wisconsin": 10, - "Wyoming": 3, -} - -counted_locations = {} - -def choose_vote_location(candidate_1_electoral_votes, candidate_2_electoral_votes): - location = input("\nSelect your location (or type 'end' to end election): ").strip() - - if location in electoral_votes_locations: - print(location) - state_voting(location, candidate_1_electoral_votes, candidate_2_electoral_votes) - elif location != "end" and location not in electoral_votes_locations: - print("Invalid State Chosen") - elif location == "end": - end_election() - - return location - -def state_voting(location, candidate_1_electoral_votes, candidate_2_electoral_votes): - global candidate_1_popular_votes, candidate_2_popular_votes # Access global variables - - if location in counted_locations: - print(f"{location} has already closed their polling places and decided their votes.") - else: - candidate_1_state_votes = 0 - candidate_2_state_votes = 0 - total_state_votes = 0 - winner = "" - - while True: - vote = input( - f"Vote for Candidate 1 ('1') or Candidate 2 ('2') or close ('close') the polls. " - ) - - if vote not in ["1", "2", "CLOSE", "close"]: - print("Invalid selection") - else: - if vote == "1": - candidate_1_state_votes += 1 - candidate_1_popular_votes += 1 # Increment popular votes - total_state_votes += 1 - continue - elif vote == "2": - candidate_2_state_votes += 1 - candidate_2_popular_votes += 1 # Increment popular votes - total_state_votes += 1 - continue - elif vote in ["CLOSE", "close"]: - print(f"-" * 60) - print(f"The total votes cast in {location} is {total_state_votes}") - print(f"-" * 60) - print(f"Candidate 1 had a total of {candidate_1_state_votes} votes") - print(f"Candidate 2 had a total of {candidate_2_state_votes} votes") - print(f"-" * 60) - - if candidate_1_state_votes > candidate_2_state_votes: - winner = "Candidate 1" - candidate_1_electoral_votes += electoral_votes_locations[location] - if candidate_2_state_votes > candidate_1_state_votes: - winner = "Candidate 2" - candidate_2_electoral_votes += electoral_votes_locations[location] - - print( - f"The winner of {location} is {winner} gaining {electoral_votes_locations[location]} electoral votes" - ) - - counted_locations[location] = [ - total_state_votes, - candidate_1_electoral_votes, - candidate_2_electoral_votes, - ] - - break - -def end_election(): - sum_votes = 0 - candidate_1_sum = 0 - candidate_2_sum = 0 - - # total up all votes cast for entire country - for k in counted_locations.keys(): - sum_votes += counted_locations[k][0] - - # total up ALL candidate 1 electoral votes from counted dictionary - for k in counted_locations.keys(): - candidate_1_sum += counted_locations[k][1] - - # total up ALL candidate 2 electoral votes from counted dictionary - for k in counted_locations.keys(): - candidate_2_sum += counted_locations[k][2] - - print(f"-" * 60) - print(f"All of the polls in the United States are closed.") - print(f"-" * 60) - print(f"Total votes cast across the country : {sum_votes}") - - print(f"-" * 60) - print(f"Candidate 1 - Total Electoral Votes : {candidate_1_sum}") - print(f"Candidate 1 - Total Popular Votes : {candidate_1_popular_votes}") # Display popular votes - print(f"-" * 60) - print(f"Candidate 2 - Total Electoral Votes : {candidate_2_sum}") - print(f"Candidate 2 - Total Popular Votes : {candidate_2_popular_votes}") # Display popular votes - print(f"-" * 60) - - if candidate_1_sum > candidate_2_sum: - print(f"Candidate 1 becomes the new President of the United States!") - if candidate_2_sum > candidate_1_sum: - print(f"Candidate 2 becomes the new President of the United States!") - print(f"-" * 60) - - raise SystemExit - -while True: - choose_vote_location(candidate_1_electoral_votes, candidate_2_electoral_votes) diff --git a/launcher.bat b/launcher.bat new file mode 100644 index 0000000..b616d29 --- /dev/null +++ b/launcher.bat @@ -0,0 +1,28 @@ +@echo off +REM Save the current directory +pushd %~dp0 + +REM Check if main.py exists +if not exist main.py ( + echo Error: main.py not found in the current directory. + popd + pause + exit /b 1 +) + +REM Run the Python script and check for errors +echo Running main.py... +python main.py +if %errorlevel% neq 0 ( + echo Error: main.py did not run successfully. Error level: %errorlevel% + popd + pause + exit /b %errorlevel% +) + +REM Provide success feedback +echo main.py ran successfully. + +REM Return to the original directory +popd +pause