简体   繁体   English

如何使程序停止并从最低到最大打印输入?

[英]How to make a program stop and print inputs from lowest to greatest?

How do I make it so it stops the program in any form of "stop" like StOp or STOP (case sensitive). 我如何使它以任何形式的“停止”(如StOp或STOP(区分大小写))停止程序。 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)
  1. To check for stop case-insensitively, you can convert the input to lowercase and compare against stop . 要不区分大小写地检查stop ,可以将输入转换为小写并与stop比较。

     if not grades or grades.lower() == 'stop': 
  2. To sort the data and print in ascending order, you can use zip and sorted 要对数据排序并按升序打印,可以使用zipsorted

     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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何找到给定点的最大长度并使程序在最大长度到达中间的那个点之后停止? - how do i find the greatest length from a given point and make the program stop after that point with the greatest length hits the middle? 如何使 Python 从 5 个输入(简单)方式中选择最大的数? - How to make Python choose the greatest number from 5 inputs(simple)way? 如何对字典进行排序,以便将每个键从最高值打印到最低值? - How to sort a dictionary to print from highest value to lowest for each key? 如何识别/打印字典中具有最大价值的键? - How to identify/print the key with the greatest value in a dictonary? 如何在 python 中打印每行的最大总和? - how to print greatest sum each rows in python? 如何从 kivy 中的循环打印文本输入 - how to print the text inputs from the loop in kivy 如何让这个程序停止运行? - How to I make this program stop running? 如何使用热键停止程序(在控制台外) - how to make program stop with a hotkey (outside the console) 如何使用“ while”制作一个python程序来打印为0? - how to make a python program using “while” to print at 0? 当输入 < 0 并且最低税率相同时,如何使代码停止,然后打印出以下国家/地区 - How can I make the code stop when input < 0 and when lowest tax is the same then it prints out the following countries
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM