Computers and Technology

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

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:00, king514
6. the is particularly susceptible to the effects of alcohol because it receives a large portion of total blood flow and has a high concentration of neurons. a. heart b. pancreas c. brain d. liver
Answers: 2
image
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
image
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
image
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
Do you know the correct answer?
Filter and sort a list Write a program that gets a list of integers from input, and outputs non-neg...

Questions in other subjects:

Konu
Mathematics, 14.03.2022 18:20
Konu
English, 14.03.2022 18:20