[Python] Counters and accumulators not resetting in nested while loops

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently writing a program that should take inputs about a hockey league. My issue is that the while loops are not working reseting back to the beginning of the loop when the program encounters a flag. There are two flags, xxxx, being the flag to finish the input loop for game details, and Done, when the inputs for the teams are finished. I have an issue that instead of resetting the various running counts for each team, the program adds together all the inputs when it should have reset to zero for each new team. Here is my program.

    print("Project 4C authored by Cam Kelly")
    week = input("Input Week Number: ")
    #initalizing League Level
    most_improved_team = None
    most_improved_points = 0
    points_leader_team = None
    points_leader = 0
    ppg_leading_team = None
    ppg_leading_avg = 0
    highest_goal_game = None
    highest_goal_total = 0
    ppg = 0
    #Starting and initalizing the Team Code Loop
    team_code = input("Team Code: ")
    while(team_code) != ("Done") or (team_code) != ("done"):
    previous_points = input("Previous Points: ")
    game_count = 0
    largest_margin = 0
    week_points = 0
    game_code = input("Game Code: ")
    total_points = 0
    #Starting and initalizaing the Game Code Loop
    while game_code != ("XXXX") or game_code != ("xxxx"):
    win = 2
    loss = 0
    otl = 1
    #Starting the Inputs for the Game Level
    goals_for = input("Goals For: ")
    goals_against = input("Goals Against: ")
    overtime = input("Overtime Y/N: ")
    #Determining Points Earned
    if float(goals_for) > float(goals_against):
    week_points = int(week_points) + 2
    points_awarded = win
    elif float(goals_for) < float(goals_against) and overtime == ("Y") or overtime == ("y"):
    week_points = int(week_points) + 1
    points_awarded = otl
    else:
    week_points = int(week_points) + 0
    points_awarded = loss
    #Incramenting game count, total goals and updating largest margin and total goals
    game_count = int(game_count) + 1
    margin = abs(int(goals_for) - int(goals_against))
    if float(margin) > float(largest_margin):
    largest_margin = margin
    total_goals = int(goals_for) + int(goals_against)
    if int(total_goals) > int(highest_goal_total):
    highest_goal_game = game_code
    highest_goal_total = total_goals
    #Outputting Game Outputs and restarting the game loop
    print("Game Code:",game_code)
    print("Points Awarded:",points_awarded)
    game_code = input("Game Code: ")
    #Ending the Game loop and restarting the team loop also outputting team outputs
    if game_code == ("XXXX") or game_code == ("xxxx"):
    ppg = float(week_points) / float(game_count)
    total_points = int(previous_points) + int(week_points)
    print("Team Code:",team_code)
    print("Current Points:",total_points)
    print("Points Per Game:",ppg)
    print("Largest Margin:",largest_margin)
    team_code = input("Team Code: ")
    if int(week_points) > int(most_improved_points):
    most_improved_points = week_points
    most_improved_team = team_code
    if int(total_points) > int(points_leader):
    points_leader = total_points
    points_leader_team = team_code
    if float(ppg) > float(ppg_leading_avg):
    ppg_leading_team = team_code
    ppg_leading_avg = ppg
    print("Team Code:",team_code)
    print("Current Points:",total_points)
    print("Points Per Game:",ppg)
    print("Largest Margin:",largest_margin)
    team_code = input("Team Code: ")
    game_code = input("Game Code: ")
    #ending team loop and outputting the league level outputs
    if(team_code) == ("Done") or ("done"):
    print("Week Number:",week)
    print("Current Leading Team:", points_leader_team)
    print("Current Leader Points:",points_leader)
    print("Most Improved Team:",most_improved_team)
    print("Points Earned This Week By The Most Improved Team:",most_improved_points)
    print("Team With The Highest Points Per Game:",ppg_leading_team)
    print("Highest Points Per Game:",ppg_leading_avg)
    print("Highest Scoring Game:",highest_goal_game)
    print("Goals Scored In The Highest Scoring Game:",highest_goal_total)

    Continue reading...

Compartilhe esta Página