Leccion 36 python. Suma de numeros consecutivos | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 8

Leccion 36 python. Suma de numeros consecutivos

Se supone que debia usar bucles, rangos, etc. Pero consegui el resultado con 2 lineas de codigo. Alguien lo hizo diferente? n = int(input()) print (int ((n * (n+1)) /2))

21st Jun 2021, 7:48 PM
Franco Zeballos
Franco Zeballos - avatar
7 Respostas
+ 3
yo lo reolvi de la siguiente manera; N = int(input()) #tu cĆ³digo va aquĆ­ numbers=list(range(0,N+1)) total=0 for n in numbers: total= total+numbers[n] print (total)
28th Jun 2022, 5:33 PM
Johnny Molina
Johnny Molina - avatar
+ 2
its about practice on loops.. how to use loops.. but not about only solving. n = int (input ()) print ((n * (n + 1)) // 2)) other way : print(sum(range(1,int(input())+1))) so many ways.. but need to try as lesson instructed.. hope it helps...
21st Jun 2021, 7:58 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
La verdad es que la plataforma en este punto creo que se desmarca un poco de lo que la leccion enseƱa hasta este momento... No digo que este mal, porque te incita a investigar, pero no se puede resolver con los conocimientos que te ofrece. Por lo menos en mi caso.
29th Apr 2022, 9:53 PM
Luis F Arias
Luis F Arias - avatar
0
La idea es usar for pero yo lo hice de esta forma jeje: N = int(input()) #your code goes here n= 5 A= range(1, N+1) B=list(A) Sumalista = sum(B) print (Sumalista)
23rd May 2022, 5:32 PM
Danniel Gonzalez
Danniel Gonzalez - avatar
0
Can someone try this code? It always gives me an error at the end of the for line N = int(input()) #tu cĆ³digo va aquĆ­ resultado = 0 X=list(range(0,N) for a in X: resultado += a print(resultado)
5th Jul 2022, 9:36 AM
emilio cuevas
0
Esto me funcionĆ³: N = int(input()) #tu cĆ³digo va aquĆ­ Y = 0 for i in range(1, N+1): Y += i print(Y)
31st Aug 2022, 12:12 PM
Lucas Quinteros
Lucas Quinteros - avatar
- 1
Son validas pero la idea es afianzar comocimientos sobre itinerancias yo lo hice asi N = int(input()) #tu cĆ³digo va aquĆ­ N+=1 N=list(range(N)) total=0 for i in N: total+= N[i] print (total)
29th Sep 2021, 1:23 AM
alejandro rubio penagos
alejandro rubio penagos - avatar