Beginner Index out of range in python -


this problem working on class (below question , code wrote):

the program should accept series of students , exam scores in response "?" prompt. enter 2 digit exam score (no 1 ever gets 100 or less 10), single space , name of student. keep entering these until user enters "stop" – program should able handle form of "stop" – example, "stop", "stop", "stop", "stop", etc. should display list of student names ordered exam scores (low high). instance (user input underlined):

? 23 warren ? 44 dona ? 33 tom ? stop warren tom dona 

so understand i've written , understand not complicated problem. though, way code written, when input "stop" show program finished inputs, runs input "stop" in loop creating index out of range error. how can make run "stop" in while loop , not in loop?

    students = []     namescore = ""     while (namescore.lower() != "stop"):         namescore = input ("? ")         students.append(namescore)      students.sort()      student in students:         x = student.split()         print (x[1]) 

if "break" before append, "stop" not included in students.

while true:     namescore = input ("? ")     if namescore.lower() == "stop": break     students.append(namescore) 

moreover, if write while-loop way, won't need pre-initialize namescore.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -