Dude, your question is not clear at all, but correct me if I got it wrong.
You want to make a sum. Add from the value n1 to the value N2.
Example: n1 = 1
and n2 = 5
. The result will be 10, since 1+2+3+4 = 10.
That’s what you implied.
Logic
You declare a counter variable that starts with n1
and makes it incremented until it reaches the limit, which is n2
.
Solution in Python
Note: You do with the loop you prefer, I chose the while
because it was faster.
n1 = int(input("Digite o valor de n1: "))
n2 = int(input("Digite o valor de n2: "))
soma = 0
i = n1
while i < n2: //Para somar o n2 também, é só colocar <=
soma = soma + i
i = i + 1
print("O valor da soma é = ", soma)
That’s it. Let me know if that’s it.
Your question is not clear. Could [Dit] and give examples of what you need?
– Woss
print(a + b)
.– Victor Stafusa
@Andersoncarloswoss I edited.
– user143390
And why is the output 3 for input 1 and 3? Would the sum 1+2? And if the input is 1 and 7, what should be the output?
– Woss
The input and output values and description were taken from the run.codes where my teacher passes the questions, and sometimes he puts some wrong information in the questions
– user143390
@Sonogoku They are not necessarily wrong, but they are insufficient to understand the issue. Edit the question and transfer the full statement of the exercise.
– Woss
Wait a minute! What is this becoming? A simple "do and deliver me" ?
– Cleyton
resultado = list(range(numero1,numero2))
print (sum(resultado))
that was the calculation that did what I wanted– user143390