Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


A Fun Python Progress Bar for Beginners! 🚀 filter_list
Author
Message
A Fun Python Progress Bar for Beginners! 🚀 #1
Hey fellow Python lovers! 🐍

If you’re new to Python and want to try something simple but cool, I’ve got a fun little project for you: a text-based progress bar! It’s an awesome way to show off how loops, strings, and time delays work in Python, and it looks pretty cool when it runs. 😎

Here’s the code:

Code:
import time
import sys

def loading_bar():
    print("Loading...")
    for i in range(101):
        # Simulate the loading progress
        time.sleep(0.1)
        sys.stdout.write(f"\r[{('=' * i).ljust(100)}] {i}%")
        sys.stdout.flush()
    print("\nFinished!")

loading_bar()

So... what does it do?
The program starts with the text "Loading..." to get you hyped! 🏃‍♂️
It runs a loop 101 times (from 0 to 100), simulating the loading process.
Every time it loops:
It waits for 0.1 seconds (time.sleep(0.1)), just like a real loading screen.
It uses sys.stdout.write to print the progress bar on the same line (so it doesn't flood the console with new lines).
The progress bar gets longer with each loop ('=' * i), filling up as it goes.
Once it hits 100%, it prints "Finished!" like a boss. 🎉
Why is this cool?
Loops + Strings: It’s a nice way to get comfortable with loops and string manipulation in Python.
Real-time Output: The magic happens with \r, which lets you overwrite the same line in the console—so it looks like the progress bar is actually filling up.
Time Delay: The time.sleep(0.1) makes the loading feel like it's actually doing something.

And there goes you lesson for today HAPPY CODING

Reply







Users browsing this thread: 1 Guest(s)