Question

Create a python script that reads in an unknown number of positive numbers and negative numbers....

Create a python script that reads in an unknown number of positive numbers and negative numbers. These numbers are to be stored in two different collections. Once the user enters a zero value, the script will output all of the values in both collections, separately.

Sample Usage/Output:

Please enter a positive or negative number (enter a zero to end): 5

Please enter a positive or negative number (enter a zero to end): -7

Please enter a positive or negative number (enter a zero to end): 8

Please enter a positive or negative number (enter a zero to end): 9

Please enter a positive or negative number (enter a zero to end): -1

Please enter a positive or negative number (enter a zero to end): 0

Positive Values Entered: [5.0, 8.0, 9.0]

Negative Values Entered: [-7.0, -1.0]

Homework Answers

Answer #1

# If you have a query/issue with respect to the answer, please drop a comment. I will surely try to address your query ASAP and resolve the issue

# # Please consider providing a thumbs up to this question if it helps you. by doing that, you will help other students who are facing a similar issue.

#-----------------------------OUTPUT/INPUT--------------------------------

#----------------------------------------------------------------------------------------

#initializes empty collections

positives=[]

negatives=[]

# promtps for the first number

number=float(input("Please enter a positive or negative number (enter a zero to end):"))

# loops until user enters 0

while(number!=0):

    # if the number is negative

    if(number<0):

        # adds to the collection of negatives

        negatives=negatives+[number]

    else:

        # adds to the collection of positives

        positives=positives+[number]

    #prompts the user

    number=float(input("Please enter a positive or negative number (enter a zero to end):"))

print("Positive Values Entered:",positives)

print("Negative Values Entered:",negatives)


#-----------------------------------------------------------------------

#_---------------------------------------------------------------------------------------

#----------

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
python: find the maximum value from a sequence of positive numbers. you should print out the...
python: find the maximum value from a sequence of positive numbers. you should print out the maximum number from the sequence. output: Keep entering positive numbers. enter a number: enter a number: enter a number: enter a number: enter a number: largest number entered: ...
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
python If a number num1 divides another number num2 evenly then num1 is a divisor of...
python If a number num1 divides another number num2 evenly then num1 is a divisor of num2. For example, 2 is a divisor of 2, 4, 6, 8, but 2 is not a divisor of 1, 3, 5, 7, 9, 11, 13. Write a function named count_divisors(m,n) that works as follows. Input: the function takes two integer arguments m and n Process: the function asks the user to enter numbers (positive or negative), and counts the total number of inputs...
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT