Skip to content

german-boop/Simple-Sum-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

calculater


๐ŸŽจBadges

PYTHON lICENSE Code size


๐Ÿงฎ Simple Sum Calculator

A minimal Python program that calculates the sum of numbers from 1 to 100.

How to Run

python sum.py

## How to Run
```bash
python sum.py

๐Ÿš€ Quick Start

# Clone the repository
git clone https://github.com/yourusername/sum-calculator.git
cd sum-calculator

# Run the program
python sum.py

๐Ÿ’ป Core Code

# sum.py
"""
Simple Sum Calculator: 1 to 100
Calculates the sum of numbers from 1 to 100 using an iterative approach.
"""

# Initialize accumulator
total = 0

# Iterate through numbers 1 to 100
for i in range(1, 101):
    total += i  # Add current number to total

# Display result
print("Sum from 1 to 100:", total)

๐ŸŽฏ Mathematical Proof

Sum = n ร— (n + 1) รท 2
    = 100 ร— 101 รท 2
    = 5050

1 + 2 + 3 + 4 + โ‹ฏ

The infinite series whose terms are the positive integers 1 + 2 + 3 + 4 + โ‹ฏ is a divergent series. The nth partial sum of the series is the triangular number which increases without bound as n goes to infinity. Because the sequence of partial sums fails to converge to a finite limit, the series does not have a sum.

image


Simple example

# Calculate the sum of numbers from 1 to 100
total = 0

for i in range(1, 101):
    total += i

print("Sum from 1 to 100:", total)

๐Ÿ“Š Expected Output

Sum from 1 to 100: 5050

โšกEnhanced Animated Version

Would you like to see the calculation in action? Check out the animated version!

import time
import sys

def calculate_with_animation():
    """ Calculate sum with visual progress animation."""
    total = 0
    
    print("๐Ÿงฎ Calculating sum of 1 to 100...\n")
    
    for i in range(1, 101):
        total += i
        
        # Progress bar animation
        progress = i // 2
        bar = "โ–ˆ" * progress + "โ–‘" * (50 - progress)
        
        sys.stdout.write(f"\r[{bar}] {i:3d}/100 | Current: {i:3d} | Total: {total:6d}")
        sys.stdout.flush()
        time.sleep(0.02)
    
    print("\n\n" + "โ•" * 60)
    print(f"โœจ Final Result: {total}")
    print("โ•" * 60)

if __name__ == "__main__":
    calculate_with_animation()

๐Ÿ“Š Expected Output

๐Ÿงฎ Calculating sum of 1 to 104...

[โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ] 103/104 | Current: 103 | Total:   5356

โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
โœจ Final Result: 5356
โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿ“ˆ Performance Metrics

Metric Value Details
โฑ๏ธ Execution Time ~0.0001s Almost instantaneous
๐Ÿ”„ Iterations 100 Fixed loop count
๐Ÿ’พ Memory Usage Minimal Uses only 2 variables
๐ŸŽฏ Accuracy 100% Mathematically proven correctness

๐Ÿ› ๏ธAlternative Implementations

Method 1: Using Built-in sum()

result = sum(range(1, 101))
print(result)  # Output: 5050

Method 2: Mathematical Formula

n = 100
result = n * (n + 1) // 2
print(result)  # Output: 5050

Method 3: While Loop

total = 0
i = 1
while i <= 100:
    total += i
    i += 1
print(total)  # Output: 5050

๐ŸงชTesting the Program

# Run basic test
python sum.py

# Expected output verification
python -c "print('Test passed!' if sum(range(1, 101)) == 5050 else 'Test failed!')"

๐Ÿ“šLearning Objectives

This project demonstrates:

โœ… Basic Python syntax

โœ… Loop structures (for loops)

โœ… Variable accumulation patterns

โœ… Mathematical problem-solving

โœ… Code optimization concepts


๐ŸŒŸ Features


๐Ÿ›ก๏ธ Features & Quality

Accuracy Speed Memory Portability Readability

Feature Status Description
๐ŸŽฏ Accuracy โœ… Perfect Mathematically verified result
โšก Speed โœ… Fast O(n) time complexity
๐Ÿ’พ Memory โœ… Efficient O(1) space complexity
๐Ÿ“ฑ Portability โœ… Universal Runs on any Python 3.6+ system
๐ŸŽจ Readability โœ… Excellent Clean, well-commented, readable code

๐ŸคContributing

Found a bug or have an improvement?

  1. Fork the repository

  2. Create a feature branch (git checkout -b feature/improvement)

  3. Commit changes (git commit -m 'Add some feature')

  4. Push to branch (git push origin feature/improvement)

Open a Pull Request


๐Ÿ“License

This project is licensed under the MIT License - see the license for details.


๐Ÿ‘ฅAuthors

Primier848 - Initial work - https://github.com/german-boop


About

A minimal Python project that calculates the sum of numbers from 1 to 100.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published