Answer to Question #261597 in Python for Mikee

Question #261597

7. Negative Decimal Tally

by CodeChum Admin

We've been giving positive numbers too much attention lately, it's time to let negative numbers take the spotlight this time!


Instructions:

  1. Input four float numbers; they could be positive or negative.
  2. Only add all inputted negative numbers, and print its sum, up to 2 decimal place.
  3. Hint: The previous/latest topic is about if-else-elseif statements, but do we need one here?

Instructions

  1. Input four decimal numbers, they could be positive or negative.
  2. Add all the negative numbers, and print the sum, up to 2 decimal places.

Input

A line containing four decimals/floats separated by a space.


-30.22·10.5·-2.2·-1.8

Output

A line containing a negative decimal/floats with two decimal places.


-34.22
1
Expert's answer
2021-11-11T00:06:42-0500
#creating a varieble to input our numbers
numbers = input("Enter four float numbers which are separated with a space:")




N = numbers.split(" ")
sum_of_neg = 0.0
#creating a loop and condition to find the sum
for i in N:
    x = float(i)
    if (x < 0):
        sum_of_neg += x


print("{:.2f}".format(sum_of_neg))


#This code is written by expert Suhrob Umarov

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment