Python Forum
Help with arrays assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with arrays assignment
#1
Good evening. I am new to coding and python this is my fourth week in class. The assignment was

Statistics on football games are often displayed as the number the points each team (home and visitor) scored in each of four quarters. Write a program to create an array for the home team scores and another array for the visiting team scores. The program should ask for the name of the home team and the visiting team. It should also ask for the number of points each team scores per quarter. Then, based on that input, it will create a text chart with the data and the total number of points for each team.
The program should look like this. Remember, anything after a “>” is user input. Also, don't worry if you can't get the number to line up nicely in columns.
Output:
Enter the home team's name? >Mountaineers Enter the visiting team's name? >Fighting Irish How many points did the Mountaineers score in quarter 1? >7 How many points did the Fighting Irish score in quarter 1? >7 How many points did the Mountaineers score in quarter 2? >10 How many points did the Fighting Irish score in quarter 2? >7 How many points did the Mountaineers score in quarter 3? >0 How many points did the Fighting Irish score in quarter 3? >14 How many points did the Mountaineers score in quarter 4? >21 How many points did the Fighting Irish score in quarter 4? >0 Total Statistics Quarter Mountaineers Fighting Irish 1 7 7 2 10 7 3 0 14 4 21 0 Total 38 28
I did the following code
team1 = [""]
team2 = [""]
team1[0] = input("Enter the home team's name?")
team2[0] = input("Enter the visiting team's name?")
team_1 = ["","","",""]
team_2 = ["","","",""]
team_1[0] = eval(input("How many points did the", team1 ,"score in quarter 1?"))
team_2[0] = eval(input("How many points did the", team2 ,"score in quarter 1?"))
team_1[1] = eval(input("How many points did the", team1 ,"score in quarter 2?"))
team_2[1] = eval(input("How many points did the", team2 ,"score in quarter 2?"))
team_1[2] = eval(input("How many points did the", team1 ,"score in quarter 3?"))
team_2[2] = eval(input("How many points did the", team2 ,"score in quarter 3?"))
team_1[3] = eval(input("How many points did the", team1 ,"score in quarter 4?"))
team_2[3] = eval(input("How many points did the", team2 ,"score in quarter 4?"))
print("Total Statistics")
I keep getting the following error: TypeError: input expected at most 1 arguments, got 3
I know its because its reading 3 arguments in my lines, however I can't figure out how to make it one argument and pull the team data. I tried googling some stuff but all those arguments were using numbers so I was kind of confused. I'd appreciate any help.
Reply
#2
Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time.

The input function is not like the print function, it only takes one parameter. So you need to make one string to pass to it. Check out the format method of strings. If you are using Python 3.6 or later, you may want to look into f-strings.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Sorry about that I will make sure to post correctly next time. The section you have as output is just an example of how it is supposed to work. So from what I read I'm supposed to use the str function. I'm just confused as to how. The eval input stuff I got pretty easy arrays are a bit confusing, I read the link you listed but I'm still confused as to how to use the function
Reply
#4
Oh, I didn't notice you were using eval. That's overkill, use int instead. The team_1 and team_2 should be initialized to a list of zeros ([0, 0, 0, 0]). You say you're supposed to use str, have you covered adding strings together?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
I was saying that based off of the like you put. The main problem is getting the team name to appear and not get the error i first posted. Also, I don't understand initializing to a list. I thought when the user types in the name or score that was putting it to a list
Reply
#6
(Jan-30-2019, 02:23 AM)hyg71886 Wrote: The main problem is getting the team name to appear and not get the error i first posted

That's why I asked you about adding strings. Have you covered that in your class?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
no not yet
Reply
#8
Okay, then:

print('What {} is confusing you about the format method?'.format('specifically'))
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#9
(Jan-30-2019, 02:52 AM)ichabod801 Wrote: Okay, then:

print('What {} is confusing you about the format method?'.format('specifically'))

So I took your advice and changed the eval to int. Whats confusing me is why how to get a line like
team_1[0] = int("How many points did the home", team1 , "score in quarter 1?")
to take the name from the team1 list created from the first question and insert it. Again I get that it's reading as three things I'm just not understanding how to write the line so it takes the input from the enter the home teams name line and input it when asking for scores. It could be something really simple here I'm missing but even after rereading everything, youtube, reading through the forums I still don't get it.
Reply
#10
First, you want to replace just eval with int. In the line you have there, you are replacing eval AND input with int.

Second, I gave you an exact example of how to insert the team name in my last post. What about that did you not understand?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

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