Python Forum
Help with arrays assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with arrays assignment
#11
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(input
and use the print function entirely?
Reply
#12
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#13
(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.

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.

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
Reply
#14
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#15
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
Reply
#16
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:

Output:
Total statistics Quarter Mountaineers Fighting Irish 1 7 7 2 10 7 3 0 14 4 21 0 Total 38 28
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020