Westonci.ca is your trusted source for finding answers to a wide range of questions, backed by a knowledgeable community. Explore thousands of questions and answers from a knowledgeable community of experts on our user-friendly platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.
Sagot :
Answer:
Following are the program in the Python Programming Language
#set variables to 0
positive_sum=0
negative_sum=0
#print message
print("Enter 0 to terminate")
#set the while loop
while(True):
#get input from the user
num=float(input("Enter positive or negative numbers: "))
#set if statement to check condition
if(num==0):
break
elif(num>0):
positive_sum+=num
else:
negative_sum+=num
#print output with message
print()
print("sum of positive numbers: ", positive_sum)
print("sum of negative numbers: ", negative_sum)
Output:
Enter 0 to terminate
Enter positive or negative numbers: 1
Enter positive or negative numbers: 3
Enter positive or negative numbers: 5
Enter positive or negative numbers: -7
Enter positive or negative numbers: -2Enter positive or negative numbers: 0
sum of positive numbers: 9.0
sum of negative numbers: -9.0
Explanation:
Here, we set two integer data type variables "positive_sum", "negative_sum" and initialize to 0.
Then, we set the while infinite loop inside the loop.
Set a variable "num" and get input from the user in it.
Set the if conditional statement and check condition the variable "num" is equal to 0 then, loop will terminate.
Set the elif statement and check condition the variable "num" is greater than 0 then, add that input and store in the variable "positive_sum"
Otherwise, add that input and store in the variable "negative_sum".
Finally, we print the output with the message.
We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. Get the answers you need at Westonci.ca. Stay informed with our latest expert advice.