Home Chapters Projects About
HomeProjects › Day 58
DAY 58 — 60 DAY PYTHON CHALLENGE

URL Validator

Python mein URL Validator banao — Hindi mein step by step

Advertisement

Project kya hai?

Day 58 ka project hai URL Validator! Yeh project banane se aap Python ke important concepts practice kar payenge. Neeche complete code hai — copy karo aur chalao!

Complete Python Code

python — url_val.py
import re

def validate_url(url):
    pattern = r'^https?://[^\s/$.?#].[^\s]*$'
    return bool(re.match(pattern, url))

def analyze_url(url):
    try:
        secure   = "HTTPS (Secure)" if url.startswith("https") else "HTTP (Not Secure)"
        after    = url.split("//")[1]
        domain   = after.split("/")[0]
        tld      = domain.split(".")[-1]
        has_path = "/" in after
        has_q    = "?" in url
        print(f"  Protocol : {secure}")
        print(f"  Domain   : {domain}")
        print(f"  TLD      : .{tld}")
        if has_path:
            print(f"  Has Path : Yes")
        if has_q:
            print(f"  Has Params: Yes")
    except:
        pass

test_urls = [
    "https://www.pythonhindi.in",
    "http://example.com/page",
    "https://api.site.com?key=123",
    "not-a-url",
    "ftp://wrong.com",
    "https://blog.python.org/posts",
]

print("=== URL Validator ===")
print("\nTest Results:")
print("-" * 50)
for u in test_urls:
    status = "Valid  " if validate_url(u) else "Invalid"
    print(f"  [{status}] {u}")

print("\nApna URL check karo:")
while True:
    url = input("URL (q=quit): ")
    if url == "q": break
    if validate_url(url):
        print("\n  Valid URL!")
        analyze_url(url)
    else:
        print("  Invalid URL!")
    print()
OUTPUT
Test Results:
--------------------------------------------------
  [Valid  ] https://www.pythonhindi.in
  [Valid  ] http://example.com/page
  [Invalid] not-a-url
  [Invalid] ftp://wrong.com

Apna URL check karo:
URL: https://www.pythonhindi.in
  Valid URL!
  Protocol : HTTPS (Secure)
  Domain   : www.pythonhindi.in
  TLD      : .in

Code kaise kaam karta hai?

Regex se URL pattern validate hota hai. HTTPS secure hai, HTTP nahi. split('//') aur split('/') se URL parts nikale jaate hain.
Advertisement

📋 Project ka Introduction

URL Validator Python ka Day 58 ka project hai. Is project mein aap Python ke important concepts practice karenge jo real-world applications mein bahut use hote hain.

Yeh project beginners ke liye design kiya gaya hai lekin kaafi concepts cover karta hai. Step by step samjho, code chalao, aur khud modify karke practice karo.

Is tarah ke projects banane se aapka Python confidence badh jaata hai aur aap asli problems solve karna seekh jaate hain. Chaliye code samjhte hain!

🧠 Is Project mein kya seekhoge?

Yeh project banate waqt aap ye Python concepts use karoge:
ConceptKya karta hai
VariablesData store karna
FunctionsReusable code blocks
LoopsRepeat karna
ConditionsDecisions lena
Input/OutputUser se interact karna

📝 Code kaise kaam karta hai — Step by Step

Neeche code ki poori logic step-by-step samjhayi gayi hai:
  1. Problem samjho: URL Validator mein kya karna hai
  2. Required variables aur data structures decide karo
  3. Logic step-by-step likhó
  4. Code mein implement karo
  5. Test karo aur bugs fix karo

⚠️ Common Mistakes — Bhool mat jaana!

Beginners yeh galtiyan aksar karte hain — dhyan rakho:
  • ⚠️ Indentation sahi rakho — Python mein spaces matter karti hain
  • ⚠️ Variables ko use se pehle define karo
  • ⚠️ Input ko int()/float() mein convert karo agar number chahiye
  • ⚠️ Edge cases handle karo — kya hoga agar user galat input de?

🏋️ Practice Exercises — Aage badho!

Yeh project complete karne ke baad in exercises se practice karo:
  • 💡 URL Validator mein naya feature add karo
  • 💡 Code ko functions mein refactor karo
  • 💡 Error handling improve karo
  • 💡 File mein data save karo

❓ Aksar Pooche Jane Wale Sawal (FAQ)

Q: URL Validator project kyon banana chahiye?

A: Har project ek naya concept sikhata hai. Practice se hi Python fluent aati hai.
Q: Code run nahi ho raha?

A: Indentation check karo, syntax errors dekho, variables define hain ya nahi check karo.
Q: Kaise improve karein?

A: Pehle basic version complete karo, phir ek ek feature add karte jao.