I'm writing a program to keep track of baseball team ratings. I would like the user to be able to input the name abbreviations of the teams that have played, the runs scored for each, and have the program update their ratings accordingly.
I list each team in a list called teams
and create a new list of chronological ratings for each team with an initial rating of 1500:
teams = ["ARI","ATL","BAL","BOS","CHC","CWS","CIN","CLE","COL","DET",
"HOU","KC","LAA","LAD","MIA","MIL","MIN","NYM","NYY","OAK",
"PHI","PIT","SD","SEA","SF","STL","TB","TEX","TOR","WSH"]
for team in teams:
team = [1500]
So every team abbreviation now has an associated list with an initial value of [1500]
, which will be appended with each new rating. Outside that declaration, I attempt to have the user reference which team list they would like to append a new rating to (after the program calculates the difference):
def gameIn(at="None", ht="None"):
while at.upper() not in teams:
at = input("Enter away team abbreviation: ")
at = at.upper()
if at not in teams:
print("Team selection invalid, try again")
while True:
try:
atr = int(input("Runs: "))
except ValueError:
print('Error: improper score.')
continue
break
while ht.upper() not in teams:
ht = input("Enter home team abbreviation: ")
ht = ht.upper()
if ht not in teams:
print("Team selection invalid, try again")
elif at == ht:
print("Home team and away team cannot be the same, try again")
while True:
try:
htr = int(input("Runs: "))
except ValueError:
print('Error: improper score.')
continue
break
htOldRating = ht[-1]
atOldRating = at[-1]
print(htOldRating)
print(atOldRating)
The last two statements will simply print the last letter in each team name, meaning the global list of teams and team rating lists are not accessed by the function and new local variables of string type are being declared. Is it possible to have the user input the list variable name they want to access and have the program recognize it as such?