![]() |
Help with arrays assignment - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Help with arrays assignment (/thread-15750.html) Pages:
1
2
|
RE: Help with arrays assignment - hyg71886 - Jan-30-2019 So should it be something like this? team_1[0] = int(input('How many points did the {} score in quarter 1?'.format(team1))When I try that I keep getting errors. I tried it a couple different ways but it did the same thing. I thought the {} would hold the spot for the team and then print it which is why format goes towards the end. Or do I need to lose the int(inputand use the print function entirely? RE: Help with arrays assignment - ichabod801 - Jan-30-2019 team1 is a list. You need to use a string. team1[0] is the string of the team's name. I could use a little help here. "I'm getting errors" is vague. I was able to figure it out this time, but I might not be able to figure it out next time. When you get an error, please post the full text of the error. RE: Help with arrays assignment - hyg71886 - Jan-30-2019 (Jan-30-2019, 03:28 AM)ichabod801 Wrote: team1 is a list. You need to use a string. team1[0] is the string of the team's name. Ok I will be more descriptive. So I put in the line like so team_1[0] = int(input('How many points did the {} score in quarter 1?'. format(team1[0]))and got unexpected EOF while parsing. Are you saying I shouldn't start the line with team_1[0] and instead use the string team1[0]? Even when I plugged that in I still received the same error. I would think I could grasp what I'm doing wrong considering I fix turbine engines smh. Thanks for the patience RE: Help with arrays assignment - ichabod801 - Jan-30-2019 You need another close parenthesis at the end of that line. You have three open and two close. That would lead Python to keep looking for more code to finish the expression. When it gets to the end of the file it gives you the error. Usually this would cause a syntax error when it got to the next statement, but you don't have any statements in the rest of your code. Edit: I'm going to bed. RE: Help with arrays assignment - hyg71886 - Jan-30-2019 OMG IT WORKED thank you so much!!! wow I can't believe I couldnt figure that out. So basically if I have how ever many of ( I have to close the line with the same amount. Wow mind blown right now RE: Help with arrays assignment - perfringo - Jan-30-2019 Now when it's worked some alternative approach. Just 'out'sane usage of f-strings :-) home = [input("Enter the home team's name: ")] visitors = [input("Enter the visiting team's name: ")] for i in range(1, 5): home.append(input(f'How many point did {home[0]} score in quarter {i}? ')) visitors.append(input(f'How many points did {visitors[0]} score in quarter {i}? ')) first, second, third = [f"<{len('Quarter')}s", f">{len(home[0]) + 2}s", f">{len(visitors[0]) + 2}s"] print('Total statistics') for i, row in enumerate(zip(home, visitors)): if i == 0: print(f"{'Quarter':{first}}{row[0]:{second}}{row[1]:{third}}") else: print(f"{str(i):{first}}{row[0]:{second}}{row[1]:{third}}") else: print(f"{'Total':{first}}{str(sum(int(x) for x in home[1:])):{second}}{str(sum(int(x) for x in visitors[1:])):{third}}")while using sample input it will give:
|