How to differentiate 2 inputs created with for loop and do operations between them

0

How do I add the two values entered by the user? My code:

for c in range(0, 2):
    n = int(input('Digite um valor:'))

How do I differentiate the first value of the second to do operations such as addition and subtraction between them?

    
asked by anonymous 21.11.2017 / 23:54

1 answer

2

There are several ways you can do this.

One of them is to create an array with all the two values entered by the user:

n = []
for c in range(0, 2):
    n.append(int(input('Digite um valor:')))

print("A soma é {}".format(sum(n)))

You can create a variable that does the operation at each loop:

sum = 0

for c in range(0, 2):
    n = int(input('Digite um valor:'))
    sum += n

print("A soma é {}".format(sum))
    
22.11.2017 / 00:00