Python Sum 1 to 100: How to Use sum() and range()
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This Python program calculates the sum of all integers from 1 to 100 using the built-in sum() and range() functions. The range(1, 101) generates numbers 1 through 100, and sum() adds them together.
The result is stored in total_sum and printed with an f-string.
- Run the script to see the output: The sum of numbers from 1 to 100 is: 5050
- This is a concise and efficient way to compute arithmetic series.