0

I am writing a program for my intro CS class but I am a little stuck.
I have a designated list of names that correspond to a list of scores.
I am supposed to prompt the user to enter a name and then the program is supposed to output the name that was entered along with the corresponding score.
As I have it written now the program is printing the first name and score in the set regardless of the input. I have been stuck on this for a while, any help would be greatly appreciated!

Here is what I have right now:

names=['Jim','Sarah','Jason','Lynne','Ginny','Joe','Susan'];
scores=['88','92','95','84','85','92','89'];
input("Please enter student's name:")
for i in range (0,7):                             
    print (input(names[i] + scores[i]));
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Kaytea33
  • 1
  • 1
  • 2
    You are utterly ignoring the input. What do you expect to happen? You need to *capture* the input in a variable and then *use* that variable in the remainder of the code. Also, having the `input` inside the print statement like that really makes no sense. Perhaps you could visit your instructor during their office hours? – John Coleman Mar 12 '17 at 20:26
  • 3
    Python doesn't use semi-colons, by the way. – OneCricketeer Mar 12 '17 at 20:28
  • 3
    @cricket_007 semicolons work (they separate statements) but of course not needed here. – Jean-François Fabre Mar 12 '17 at 20:28
  • @Jean-FrançoisFabre Clarification = *as line-terminators* :) – OneCricketeer Mar 12 '17 at 20:34

3 Answers3

0

the program is supposed to output the name that was entered

That'll be hard considering you aren't capturing the input() return value.

Try this (as an example)

name = input("Please enter student's name:")
print(name)

Then, you next task is to check (in your loop) when name == <a name in the list>

Hint: You can use these for your loop rather than range(0,7)

for student in names:

or, even better, see zip lists in python

for (student, score) in zip(names, scores):
Community
  • 1
  • 1
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
0

Using the zip function, you can combine the two lists together in an easy to use 1-to-1 group of tuples.

names=['Jim','Sarah','Jason','Lynne','Ginny','Joe','Susan']
scores=['88','92','95','84','85','92','89']
data = zip(names, scores) # <- ('Jim', '88'), ('Sarah', '92'), ...

stud = input('Enter the student's name: ')
for (student, score) in data:
    if (stud == student):
        print('{} -> {}'.format(student, score))
m_callens
  • 6,100
  • 8
  • 32
  • 54
0

Better to use Python dictionaries for that:

student_scores = {'Jim': 88, 'Sarah': 92, 'Jason': 95}

and so on... Then you can call for each of them like so;

name = input("Please enter student's name: ")
print(name + 'has a score of ' + student_scores[name])
Wright
  • 3,370
  • 10
  • 27