0
How do I sum the 2 values typed by the user? My code:
for c in range(0, 2):
n = int(input('Digite um valor:'))
How to differentiate the first value of the second to do operations as sum and subtraction between them?
0
How do I sum the 2 values typed by the user? My code:
for c in range(0, 2):
n = int(input('Digite um valor:'))
How to differentiate the first value of the second to do operations as sum and subtraction between them?
2
There are many ways to 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 performs the operation on each loop:
sum = 0
for c in range(0, 2):
n = int(input('Digite um valor:'))
sum += n
print("A soma é {}".format(sum))
Very good the griffin
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
He’s opening coconuts with tanks of war?
– Jefferson Quesado
It’s just that I get the feeling that the smaller the code, the "better" it is.
– Lucas Souza
If it’s always 2, you don’t have to do the squeak.
– Woss
It seems to me that a solution that would drop a tuple on a line would be something more Pythonic
– Jefferson Quesado