How to input n numbers and sort them in Python?
You can use the built-in function sorted() in Python to sort n numbers. Here is an example code:
n = int(input("请输入数字的个数:"))
numbers = []
for i in range(n):
num = int(input("请输入第{}个数字:".format(i+1)))
numbers.append(num)
sorted_numbers = sorted(numbers)
print("排序后的数字为:", sorted_numbers)
This code first asks the user to input the number of numbers they want to enter, then uses a for loop to input each number one by one, adding them to the list “numbers”. Finally, it uses the sorted() function to sort the list “numbers” and stores the result in a variable called “sorted_numbers”, printing out the sorted numbers in the end.