Computers and Technology, 09.04.2021 22:40, Chanselor2743
Filter and sort a list
Write a program that gets a list of integers from input, and outputs non-negative integers in ascending order (lowest to highest).
Ex: If the input is:
10 -7 4 39 -6 12 2
the output is:
2 4 10 12 39
For coding simplicity, follow every output value by a space. Do not end with newline.
I have tried and come up with a TypeError on line 7. I have tried everything to fix it. A hint or help would be appreciated.
This is my code.
# asking for user input
nums = input()
lst = nums. split() # user input splits
# starting of a new list
new_list = ([])
for i in lst: # for loop to see if i in lst is true
if int(i) > 0: # if loop to see it integer is greater than 0
new_list. append(int(i)) # adding integers to the end
new_list. sort() # sorting new list in order, lowest to largest
for x in new_list: # seeing if x is true in the new list
print(x, end=' ') # printing new list in new order
Answers: 3
Computers and Technology, 23.06.2019 04:10, cvbnkifdfg
2pointswho was mikhail gorbachev? oa. a russian leader who opposed a coupob. a polish leader who founded the labor union "solidarityoc. a soviet leader who called for a closer relationship with the unitedstates, economic reform, and a more open societyd. a soviet leader who called for more oppression in the soviet union
Answers: 3
Computers and Technology, 23.06.2019 21:30, maddietomlinson113
Examine the list below. which factors positively affect lifetime income? check all that apply.
Answers: 1
Computers and Technology, 23.06.2019 21:30, shadoris26
To move a file or folder in microsoft windows, you can click and hold down the left mouse button while moving your mouse pointer to the location you want the file or folder to be, which is also known as.
Answers: 3
Filter and sort a list
Write a program that gets a list of integers from input, and outputs non-neg...
World Languages, 14.03.2022 18:20
Mathematics, 14.03.2022 18:20
Mathematics, 14.03.2022 18:20
Business, 14.03.2022 18:20
English, 14.03.2022 18:20
Mathematics, 14.03.2022 18:20