From 3b536da7d1f0831087d43acc4591242a20365dd4 Mon Sep 17 00:00:00 2001 From: Anusha <95580494+anushas-dev@users.noreply.github.com> Date: Sat, 3 Jan 2026 14:41:19 +0530 Subject: [PATCH 1/3] adding few basic scripts --- README.md | 10 +++++++--- basic/001_hello_world.py | 3 +++ basic/002_inplace_swap.py | 15 +++++++++++++++ basic/003_fstrings.py | 12 ++++++++++++ basic/004_vowel_consonants.py | 23 +++++++++++++++++++++++ basic/005_join_list_items.py | 16 ++++++++++++++++ 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 basic/002_inplace_swap.py create mode 100644 basic/003_fstrings.py create mode 100644 basic/004_vowel_consonants.py create mode 100644 basic/005_join_list_items.py diff --git a/README.md b/README.md index b513272..6e63d3c 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,12 @@ 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 | +|--------|-------------| +| [004_vowel_consonants.py](basic/004_vowel_consonants.py) | Basic example demonstrating vowel and consonant identification in a string. | +| [001_hello_world.py](basic/001_hello_world.py) | Basic Hello World Program in Python - This script prints "Hello, World!" to the console. | +| [005_join_list_items.py](basic/005_join_list_items.py) | This script takes a hyphen-separated list of hobbies from user input, | +| [002_inplace_swap.py](basic/002_inplace_swap.py) | Basic In-Place Swap Program in Python - This script swaps the values of two variables without using a temporary variable. | +| [003_fstrings.py](basic/003_fstrings.py) | Example of using f-strings for formatted string literals in Python. | diff --git a/basic/001_hello_world.py b/basic/001_hello_world.py index 888b0f5..563f8ff 100644 --- a/basic/001_hello_world.py +++ b/basic/001_hello_world.py @@ -4,3 +4,6 @@ def hello_world(): print("Hello, World!") + +if __name__ == "__main__": + hello_world() \ No newline at end of file diff --git a/basic/002_inplace_swap.py b/basic/002_inplace_swap.py new file mode 100644 index 0000000..0bf6db4 --- /dev/null +++ b/basic/002_inplace_swap.py @@ -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) \ No newline at end of file diff --git a/basic/003_fstrings.py b/basic/003_fstrings.py new file mode 100644 index 0000000..d2dab2b --- /dev/null +++ b/basic/003_fstrings.py @@ -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) \ No newline at end of file diff --git a/basic/004_vowel_consonants.py b/basic/004_vowel_consonants.py new file mode 100644 index 0000000..afe6687 --- /dev/null +++ b/basic/004_vowel_consonants.py @@ -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) \ No newline at end of file diff --git a/basic/005_join_list_items.py b/basic/005_join_list_items.py new file mode 100644 index 0000000..c754ad7 --- /dev/null +++ b/basic/005_join_list_items.py @@ -0,0 +1,16 @@ +""" +This script takes a hyphen-separated list of hobbies from user input, +prints each hobby on a new line prefixed with a *, and then +joins the hobbies into a single string separated by commas. +""" + +def join_list_items(items): + return ", ".join(items) + +if __name__ == "__main__": + hobbies = input("Enter a list of hobbies separated by hyphens (e.g., reading-cycling-cooking): ") + print("Your hobbies are:") + for item in hobbies.split("-"): + print(f"* {item}") + result = join_list_items(hobbies.split("-")) + print(f"Listing hobbies as comma-separated string: {result}") \ No newline at end of file From 3b0370aaf62164dde65f93dc33bec5b45dd7bb53 Mon Sep 17 00:00:00 2001 From: Anusha <95580494+anushas-dev@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:14:28 +0530 Subject: [PATCH 2/3] updating as per review suggestions - fstrings 002, inplace swap 003, simple list 004 --- README.md | 12 ++++++++---- basic/{003_fstrings.py => 002_fstrings.py} | 0 .../{002_inplace_swap.py => 003_inplace_swap.py} | 0 basic/005_join_list_items.py | 16 ---------------- basic/005_simple_list.py | 13 +++++++++++++ list_script.py | 15 +++++++++++++++ 6 files changed, 36 insertions(+), 20 deletions(-) rename basic/{003_fstrings.py => 002_fstrings.py} (100%) rename basic/{002_inplace_swap.py => 003_inplace_swap.py} (100%) delete mode 100644 basic/005_join_list_items.py create mode 100644 basic/005_simple_list.py diff --git a/README.md b/README.md index 6e63d3c..8520333 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,14 @@ This repository is a growing collection of clear, practical, engineer-friendly t | Script | Description | |--------|-------------| -| [004_vowel_consonants.py](basic/004_vowel_consonants.py) | Basic example demonstrating vowel and consonant identification in a string. | | [001_hello_world.py](basic/001_hello_world.py) | Basic Hello World Program in Python - This script prints "Hello, World!" to the console. | -| [005_join_list_items.py](basic/005_join_list_items.py) | This script takes a hyphen-separated list of hobbies from user input, | -| [002_inplace_swap.py](basic/002_inplace_swap.py) | Basic In-Place Swap Program in Python - This script swaps the values of two variables without using a temporary variable. | -| [003_fstrings.py](basic/003_fstrings.py) | Example of using f-strings for formatted string literals in Python. | +| [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 * | +| [001_test.py](intermediate/001_test.py) | No description found. | +| [002_test.py](intermediate/002_test.py) | No description found. | +| [003_test.py](intermediate/003_test.py) | No description found. | + diff --git a/basic/003_fstrings.py b/basic/002_fstrings.py similarity index 100% rename from basic/003_fstrings.py rename to basic/002_fstrings.py diff --git a/basic/002_inplace_swap.py b/basic/003_inplace_swap.py similarity index 100% rename from basic/002_inplace_swap.py rename to basic/003_inplace_swap.py diff --git a/basic/005_join_list_items.py b/basic/005_join_list_items.py deleted file mode 100644 index c754ad7..0000000 --- a/basic/005_join_list_items.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -This script takes a hyphen-separated list of hobbies from user input, -prints each hobby on a new line prefixed with a *, and then -joins the hobbies into a single string separated by commas. -""" - -def join_list_items(items): - return ", ".join(items) - -if __name__ == "__main__": - hobbies = input("Enter a list of hobbies separated by hyphens (e.g., reading-cycling-cooking): ") - print("Your hobbies are:") - for item in hobbies.split("-"): - print(f"* {item}") - result = join_list_items(hobbies.split("-")) - print(f"Listing hobbies as comma-separated string: {result}") \ No newline at end of file diff --git a/basic/005_simple_list.py b/basic/005_simple_list.py new file mode 100644 index 0000000..5b0c9dc --- /dev/null +++ b/basic/005_simple_list.py @@ -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) \ No newline at end of file diff --git a/list_script.py b/list_script.py index 69548d5..ff82cf3 100644 --- a/list_script.py +++ b/list_script.py @@ -1,5 +1,6 @@ import os import ast +import re from typing import List, Dict BASE_DIRS = ["basic", "intermediate", "advanced"] @@ -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: From 1f6e8d00c34999689f92a929455d42754f440459 Mon Sep 17 00:00:00 2001 From: Anusha <95580494+anushas-dev@users.noreply.github.com> Date: Tue, 6 Jan 2026 08:57:16 +0530 Subject: [PATCH 3/3] updated script to account for file name and order changes in basic,intermediate,advanced folders --- README.md | 6 ------ list_script.py | 13 ++++++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8520333..3c3e8da 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,3 @@ This repository is a growing collection of clear, practical, engineer-friendly t | [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 * | -| [001_test.py](intermediate/001_test.py) | No description found. | -| [002_test.py](intermediate/002_test.py) | No description found. | -| [003_test.py](intermediate/003_test.py) | No description found. | - - - diff --git a/list_script.py b/list_script.py index ff82cf3..6aebb44 100644 --- a/list_script.py +++ b/list_script.py @@ -61,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)