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]
# 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)
#-----------------------------------------------------------------------
#_---------------------------------------------------------------------------------------
#----------
Get Answers For Free
Most questions answered within 1 hours.