Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ This repository is a growing collection of clear, practical, engineer-friendly t

## Tutorials Index

| Filename | Description |
|----------|-------------|
| 001_hello_world.py | Basic Hello World Program in Python - This script prints "Hello, World!" to the console. |


| Script | Description |
|--------|-------------|
| [001_hello_world.py](basic/001_hello_world.py) | Basic Hello World Program in Python - This script prints "Hello, World!" to the console. |
| [002_fstrings.py](basic/002_fstrings.py) | Example of using f-strings for formatted string literals in Python. |
| [003_inplace_swap.py](basic/003_inplace_swap.py) | Basic In-Place Swap Program in Python - This script swaps the values of two variables without using a temporary variable. |
| [004_vowel_consonants.py](basic/004_vowel_consonants.py) | Basic example demonstrating vowel and consonant identification in a string. |
| [005_simple_list.py](basic/005_simple_list.py) | This script takes a list of hobbies from user input,prints each hobby on a new line prefixed with * |
3 changes: 3 additions & 0 deletions basic/001_hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

def hello_world():
print("Hello, World!")

if __name__ == "__main__":
hello_world()
12 changes: 12 additions & 0 deletions basic/002_fstrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Example of using f-strings for formatted string literals in Python.
"""

name = input("Enter your name: ")
color = input("Enter your favorite color: ")

def greet(name, color):
print(f"Hello, my name is {name} and I like the color {color}")

if __name__ == "__main__":
greet(name, color)
15 changes: 15 additions & 0 deletions basic/003_inplace_swap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Basic In-Place Swap Program in Python - This script swaps the values of two variables without using a temporary variable.
"""

a = 10
b = 20

def swap(a, b):
print(f"before swap: {a, b}")
a, b = b, a
print(f"after swap: {a, b}")
return a, b

if __name__ == "__main__":
swap(a, b)
23 changes: 23 additions & 0 deletions basic/004_vowel_consonants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Basic example demonstrating vowel and consonant identification in a string.
"""

def count_vowels_and_consonants(input_string):
"""Counts the number of vowels and consonants in the given string."""
vowels = "aeiouAEIOU"
vowel_count = 0 # Initialize vowel count
consonant_count = 0 # Initialize consonant count

for char in input_string:
if char.isalpha(): # Check if the character is a letter
if char in vowels:
vowel_count += 1 # Increment vowel count
else:
consonant_count += 1 # Increment consonant count

print(f"Vowels count: {vowel_count}, Consonants count: {consonant_count}")
return vowel_count, consonant_count

if __name__ == "__main__":
test_string = input("Enter a test string: ")
count_vowels_and_consonants(test_string)
13 changes: 13 additions & 0 deletions basic/005_simple_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
This script takes a list of hobbies from user input,prints each hobby on a new line prefixed with *
"""

def print_list_items(hobbies):
for hobby in hobbies:
print(f"* {hobby}") # Print each hobby with * prefix

if __name__ == "__main__":
hobbies = input("Enter a list of hobbies separated by commas (e.g., reading,cycling,cooking): ").split(",")
# print("Hobby List:", hobbies) # Debugging line to check the list
print("Your hobbies are:")
print_list_items(hobbies)
28 changes: 23 additions & 5 deletions list_script.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import ast
import re
from typing import List, Dict

BASE_DIRS = ["basic", "intermediate", "advanced"]
Expand All @@ -13,6 +14,20 @@ def get_py_files(base_dirs: List[str]) -> List[str]:
for file in files:
if file.endswith(".py"):
py_files.append(os.path.join(root, file))
# Deterministic ordering: sort by base-dir order, numeric filename prefix, then filename
def sort_key(path: str):
parts = os.path.normpath(path).split(os.sep)
base = parts[0] if parts else path
try:
base_index = base_dirs.index(base)
except ValueError:
base_index = len(base_dirs)
filename = os.path.basename(path)
m = re.match(r"^(\d+)", filename)
num = int(m.group(1)) if m else float('inf')
return (base_index, num, filename)

py_files.sort(key=sort_key)
return py_files

def extract_header(file_path: str) -> str:
Expand Down Expand Up @@ -46,15 +61,18 @@ def main():
with open(readme_path, "r", encoding="utf-8") as f:
readme = f.read()

# Replace or insert Tutorials Index section
# Replace or insert Tutorials Index section.
# Match from the '## Tutorials Index' header up to the next top-level '## ' header or EOF.
import re
pattern = r'(## Tutorials Index\n)([\s\S]*?)(\n\n|\Z)'
replacement = f"## Tutorials Index\n\n{table}\n"
pattern = r'(?ms)^## Tutorials Index\b.*?(?=^##\s|\Z)'
replacement = f"## Tutorials Index\n\n{table}"
if re.search(pattern, readme):
readme = re.sub(pattern, replacement, readme)
else:
# If not found, append at the end
readme += f"\n{replacement}"
# Ensure file ends with a newline before appending
if not readme.endswith("\n"):
readme += "\n"
readme += f"\n{replacement}\n"

with open(readme_path, "w", encoding="utf-8") as f:
f.write(readme)
Expand Down