Something I'm missing in this code.. How to sum the n number from the user | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Something I'm missing in this code.. How to sum the n number from the user

My code.. n = int (input("Enter the number:")) for x in range (1,n+1): print (sum(x))

1st May 2020, 3:14 PM
SelvaKumar
4 Answers
+ 1
sum =0 n = int (input("Enter the number:")) for x in range (1,n+1): sum += x print (sum) Pretty simple Stay tuned
1st May 2020, 3:20 PM
Abhay
Abhay - avatar
+ 2
print(sum(range(1,int(input("Number: "))+1)))
1st May 2020, 10:19 PM
visph
visph - avatar
+ 1
It sums iterable like list and tuple so sum(1) or that will cause error
1st May 2020, 3:25 PM
Abhay
Abhay - avatar
- 1
Got it bro.. Tuning 🔥🔥🔥🔥
1st May 2020, 3:22 PM
SelvaKumar