+ 1
End module project related doubt (sum of consecutive numbers)(python )
I have solve the project But i have doubts (question of the project is in the code itself) https://code.sololearn.com/cA24a1179A0A/?ref=app I have a doubt that can thus be solved using while loops, if yes then how? (Please don't give solutions but only suggestions)
8 Answers
+ 1
∆BH∆Y Remove the while loop and it's good
+ 3
∆BH∆Y
while True doesn't make sense here because it will run till infinite.
Try this
num = int(input())
sum = 0
while num > 0:
sum += num
num -= 1
print(sum)
+ 1
Well you got it right in the second attempt
Pay more attention to the condition given for the loop and learn the control flow of loops
0
Yes you can solve this question using while loops
Use a variable I and increase I by 1 and then add
0
∆BH∆Y or you can replace the for loop with while and remove the inner while
0
try this.
def Suma_numeros (limite):
suma=0
nmro=0
Lista_numeros=[]
while nmro<limite:
Lista_numeros.append(nmro+1)
nmro+=1
for i in Lista_numeros:
suma+= i
return suma
N= int(input())
print(Suma_numeros(N))