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?
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?
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))