В настоящее время я пишу программу, которая должна принять участие в хоккейной лиге. Моя проблема в том, что петли, которые не работают, сбрасываются в начало цикла, когда программа сталкивается с флагом. Есть два флага: xxxx, будучи флагом, чтобы закончить входной цикл для деталей игры, и сделаны, когда входные данные для команд закончены. У меня есть проблема, которая вместо сброса различных подсчетов для каждой команды, программа добавляет все входы, когда она должна быть сброшена до нуля для каждой новой команды. Вот моя программа. < /P>
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)
Подробнее здесь: https://stackoverflow.com/questions/796 ... hile-loops
Счетчики и аккумуляторы, не сброшенные в вложенных в петле ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение