Input
The four numbers
Description
N/A
Constraints
N/A
Sample
N/A
Output
The first four lines will contain message prompts to input the four numbers.
The last line will contain the sum of all positive numbers with two decimal places.
Enter·the·first·number:·12.1
Enter·the·second·number:·-321
Enter·the·third·number:·53.3
Enter·the·fourth·number:·-34
Sum·of·all·positive·numbers·=·65.40
list1 = []
for i in range(4):
n = eval(input('Enter no here: '))
if n > 0:
list1.append(n)
print('Sum of all positive integers = {}'.format(round(sum(list1), 2)))
Enter no here: 12.1
Enter no here: -321
Enter no here: -34
Enter no here: 53.3
Sum of all positive integers = 65.4
Comments
Leave a comment