How do I make it so it stops the program in any form of "stop" like StOp or STOP (case sensitive). Then how would I make it so it would print in order from lowest to greatest with the number first then name second?
names = []
while 1:
grades = input("Enter your score followed by your name")
if not grades or grades.lower() == 'stop':
break
grade_name = grades.split(" ")
grades.append(grade_name[0])
names.append(grade_name[1])
for grade, name in sorted(zip(grades, names)):
print (grades, name)
To check for stop
case-insensitively, you can convert the input to lowercase and compare against stop
.
if not grades or grades.lower() == 'stop':
To sort the data and print in ascending order, you can use zip
and sorted
for grade, name in sorted(zip(grades, names)): print grade, name
for Example
grades = [2, 3, 1] names = ["b", "c", "a"] for grade, name in sorted(zip(grades, names)): print (grade, name)
Output
1 a 2 b 3 c
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.