Computer Science, asked by pratikshajagtap8822, 1 month ago

Create a program that reads integers from the user until a blank line is entered. Once
all of the integers have been read your program should display all of the negative
numbers, followed by all of the zeros, followed by all of the positive numbers.Within
each group the numbers should be displayed in the same order that they were entered by the user. For example, if the user enters the values 3, -4, 1, 0, -1, 0, and -2 then
your program should output the values -4, -1, -2, 0, 0, 3, and 1

Answers

Answered by ajaykumaryadav021020
1

Answer:

Search...

Unlock all answers

JOIN FOR FREE

gransazer5600

04/27/2020

Computers and Technology

College

answered • expert verified

In Python please.

Create a program that reads integers from the user until a blank line is entered. Once all of the integers have been read your program should display all of the negative numbers, followed by all of the zeros, followed by all of the positive numbers. Within each group the numbers should be displayed in the same order that they were entered by the user.

For example, if the user enters the values 3, -4, 1, 0, -1, 0, and -2 then your program should output the values -4, -1, -2, 0, 0, 3, and 1. Your program should display each value on its own line.

1

SEE ANSWER

ADD ANSWER

+10 PTS

Log in to add comment

gransazer5600 is waiting for your help.

Add your answer and earn points.

Answer Expert Verified

1

frknkrtrn

Ambitious

592 answers

366.9K people helped

Answer:

negatives = []

zeros = []

positives = []

while True:

number = input("Enter a number: ")

if number == "":

break

else:

number = int(number)

if number < 0:

negatives.append(number)

elif number == 0:

zeros.append(number)

else:

positives.append(number)

for n in negatives:

print(n)

for z in zeros:

print(z)

for p in positives:

print(p)

Explanation:

Initialize three lists to hold the numbers

Create a while loop that iterates until the user enters a blank line

Inside the loop:

If the number is smaller than 0, put it in the negatives list

If the number is 0, put it in the zeros list

Otherwise, put the number in the negatives list

When the while loop is done, create three for loops to print the numbers inside the lists

Similar questions