From 67828ac991e85e25eadf586f0c78e01859bda1dd Mon Sep 17 00:00:00 2001 From: Erkhemee Date: Thu, 23 Jul 2026 19:19:31 +0800 Subject: [PATCH 1/9] Sorted the projects --- README.md | 133 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index b7cc293..73e2560 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ This repository is designed to help Python learners at all levels, starting with **Total Projects:** 44 --- -**Total Beginner Projects:** 32 +**Total Beginner Projects:** 33 -**Total Intermediate Projects:** 12 +**Total Intermediate Projects:** 11 ## Table of Contents @@ -32,53 +32,68 @@ This repository is designed to help Python learners at all levels, starting with ## Project Difficulty Ratings -| Project | Category | Difficulty | +| *Project* | *Category* | *Difficulty* | | :--- | :--- | :--- | +| **Project name** | ***Beginner** level* | Rating: 0.5 | +| [Odd or Even Checker](#28-odd-or-even-checker) | Beginner | 0.5/10 | +| [Multiplication Table Generator](#29-multiplication-table-generator) | Beginner | 0.5/10 | +| [Simple Interest Calculator](#30-simple-interest-calculator) | Beginner | 0.5/10 | +| **Project name** | ***Beginner** level* | Rating: 1.0 | +| [Anagram Checker](#31-anagram-checker) | Beginner | 1.0/10 | +| [Acronym Generator](#32-acronym-generator) | Beginner | 1.0/10 | +| [Text Reverser](#18-text-reverser) | Beginner | 1.0/10 | +| **Project name** | ***Beginner** level* | Rating: 1.5 | | [Calculator](#1-calculator) | Beginner | 1.5/10 | -| [Number Guessing Game](#2-number-guessing-game) | Beginner | 2.0/10 | -| [Password Generator](#3-password-generator) | Beginner | 2.5/10 | | [Tip Calculator](#4-tip-calculator) | Beginner | 1.5/10 | | [Temperature Converter](#5-temperature-converter) | Beginner | 1.5/10 | | [Palindrome Checker](#6-palindrome-checker) | Beginner | 1.5/10 | +| [Dice Rolling Simulator](#12-dice-rolling-simulator) | Beginner | 1.5/10 | +| [Email Slicer](#22-email-slicer) | Beginner | 1.5/10 | +| [BMI Calculator](#23-bmi-calculator) | Beginner | 1.5/10 | +| [Leap Year Checker](#27-leap-year-checker) | Beginner | 1.5/10 | +| **Project name** | ***Beginner** level* | Rating: 2.0 | +| [Number Guessing Game](#2-number-guessing-game) | Beginner | 2.0/10 | | [Word Counter](#7-word-counter) | Beginner | 2.0/10 | +| [Mad Libs Generator](#11-mad-libs-generator) | Beginner | 2.0/10 | +| [Fibonacci Sequence](#21-fibonacci-sequence) | Beginner | 2.0/10 | +| **Project name** | ***Beginner** level* | Rating: 2.5 | +| [Password Generator](#3-password-generator) | Beginner | 2.5/10 | | [Text Encryption](#8-text-encryption) | Beginner | 2.5/10 | | [Countdown Timer](#9-countdown-timer) | Beginner | 2.5/10 | | [Rock Paper Scissors](#10-rock-paper-scissors) | Beginner | 2.5/10 | -| [Mad Libs Generator](#11-mad-libs-generator) | Beginner | 2.0/10 | -| [Dice Rolling Simulator](#12-dice-rolling-simulator) | Beginner | 1.5/10 | -| [Hangman Game](#13-hangman-game) | Beginner | 3.5/10 | -| [Address Book](#14-address-book) | Beginner | 4.0/10 | -| [Pomodoro Timer](#15-pomodoro-timer) | Beginner | 3.0/10 | -| [Budget Tracker](#16-budget-tracker) | Beginner | 4.5/10 | -| [File Sorter](#17-file-sorter) | Beginner | 3.5/10 | -| [Text Reverser](#18-text-reverser) | Beginner | 1.0/10 | | [Simple Quiz Game](#19-simple-quiz-game) | Beginner | 2.5/10 | | [Prime Number Generator](#20-prime-number-generator) | Beginner | 2.5/10 | -| [Fibonacci Sequence](#21-fibonacci-sequence) | Beginner | 2.0/10 | -| [Email Slicer](#22-email-slicer) | Beginner | 1.5/10 | -| [BMI Calculator](#23-bmi-calculator) | Beginner | 1.5/10 | +| [Unit Converter](#26-unit-converter) | Beginner | 2.5/10 | | [Currency Converter](#24-currency-converter) | Beginner | 2.5/10 | +| **Project name** | ***Beginner** level* | Rating: 3.0 | +| [Pomodoro Timer](#15-pomodoro-timer) | Beginner | 3.0/10 | | [Task Tracker](#25-task-tracker) | Beginner | 3.0/10 | -| [Unit Converter](#26-unit-converter) | Beginner | 2.5/10 | -| [Leap Year Checker](#27-leap-year-checker) | Beginner | 1.5/10 | -| [Odd or Even Checker](#28-odd-or-even-checker) | Beginner | 0.5/10 | -| [Multiplication Table Generator](#29-multiplication-table-generator) | Beginner | 0.5/10 | -| [Simple Interest Calculator](#30-simple-interest-calculator) | Beginner | 0.5/10 | -| [Anagram Checker](#31-anagram-checker) | Beginner | 1.0/10 | -| [Acronym Generator](#32-acronym-generator) | Beginner | 1.0/10 | -| [Tic Tac Toe](#1-tic-tac-toe) | Intermediate | 6.0/10 | -| [Text-based Adventure Game](#2-text-based-adventure-game) | Intermediate | 5.5/10 | -| [Sudoku Solver](#3-sudoku-solver) | Intermediate | 8.5/10 | -| [Basic Sorting Algorithms](#4-basic-sorting-algorithms) | Intermediate | 6.5/10 | -| [Prime Number Sieve](#5-prime-number-sieve) | Intermediate | 5.0/10 | +| **Project name** | ***Beginner** level* | Rating: 3.5 | +| [Hangman Game](#13-hangman-game) | Beginner | 3.5/10 | +| [File Sorter](#17-file-sorter) | Beginner | 3.5/10 | +| **Project name** | ***Beginner** level* | Rating: 4.0 | +| [Address Book](#14-address-book) | Beginner | 4.0/10 | +| **Project name** | ***Beginner** level* | Rating: 4.5 | +| [Budget Tracker](#16-budget-tracker) | Beginner | 4.5/10 | +| [File viewer](#44-file-viewer) | Beginner | 4.5/10 | +| :--- | :--- | :--- | +| **Project name** | ***Intermediate** level* | Rating: 4.5 | | [Basic Caesar Cipher](#6-basic-caesar-cipher) | Intermediate | 4.5/10 | -| [Bank Account Simulator (OOP)](#7-bank-account-simulator-oop) | Intermediate | 5.5/10 | -| [File Metadata Extractor](#8-file-metadata-extractor) | Intermediate | 5.0/10 | | [CSV to JSON Converter](#9-csv-to-json-converter) | Intermediate | 4.5/10 | +| **Project name** | ***Intermediate** level* | Rating: 5.0 | +| [Prime Number Sieve](#5-prime-number-sieve) | Intermediate | 5.0/10 | +| [File Metadata Extractor](#8-file-metadata-extractor) | Intermediate | 5.0/10 | +| **Project name** | ***Intermediate** level* | Rating: 5.5 | +| [Bank Account Simulator (OOP)](#7-bank-account-simulator-oop) | Intermediate | 5.5/10 | +| [Text-based Adventure Game](#2-text-based-adventure-game) | Intermediate | 5.5/10 | +| **Project name** | ***Intermediate** level* | Rating: 6.0 | +| [Tic Tac Toe](#1-tic-tac-toe) | Intermediate | 6.0/10 | +| **Project name** | ***Intermediate** level* | Rating: 6.5 | +| [Basic Sorting Algorithms](#4-basic-sorting-algorithms) | Intermediate | 6.5/10 | | [Fractal Creator](#10-fractal-creator) | Intermediate | 6.5/10 | | [File Explorer](#11-file-explorer) | Intermediate | 6.5/10 | -| [File Viewer](#12-file-viewer) | Intermediate | 4.5/10 | - +| **Project name** | ***Intermediate** level* | Rating: 8.5 | +| [Sudoku Solver](#3-sudoku-solver) | Intermediate | 8.5/10 | ## Beginner Projects @@ -1092,6 +1107,32 @@ These projects are ideal for those new to Python. Each project includes a descri +### 44. File viewer +- **Difficulty**: 4.5/10 +- **Description**: Get filename from user, and print user's file contents. Avoid any crashes! Don't forget it must be infinte loop +- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/44_file_viewer.py - [Original](https://github.com/Ericwasepic127/Python-Projects/blob/main/Beginner/44_file_viewer.py) +- **Steps**: + 1. Ask for filename + 2. Check does file exists: If doesn't exists, show user as File Not Found. Handle it for directories too + 3. Read the file. If it encourtes permission error, notify user as operation not permitted + 4. Repeat back to 1, unless user clicks Ctrl-C (KeyboardInterrupt, SIGINT) or type `exit` at filename section +- **Tips:**: +
Tip 1: + + Make reusable function for it so it makes easier + +
+
Tip 2: + + Use `os.path.isfile` to check your file exists and it's not directory + +
+
Tip 3: + + Use `open` to handle file operation. It raises exception `PermissionError` when permission failed. Use `try/except` to catch and show user as operation not permitted + +
+ > [!NOTE] > Working code solutions are in the `/Beginner` folder. @@ -1397,34 +1438,6 @@ These projects are ideal for those with experience in Python. Each project inclu `os.path.isfile` determines whether it file or not; if it is a file, it returns `True`; if not, return `False`. - -### 12. File viewer -- **Difficulty**: 4.5/10 -- **Description**: Prompt the user for a filename and print the contents of the specified file. Ensure the program handles errors gracefully to avoid crashes. The program should run in an infinite loop until the user decides to exit. -- **Solution**: [GitHub Repository](https://github.com/Infinitode/Python-Projects/blob/main/Intermediate/12_file_viewer.py) - [Original Source](https://github.com/Ericwasepic127/Python-Projects/blob/main/Beginner/44_file_viewer.py) -- **Steps**: - 1. Prompt the user for a filename. - 2. Check if the file exists: If it does not exist, inform the user with a "File Not Found" message. Ensure to check for directories as well. - 3. Attempt to read the file. If a permission error occurs, notify the user with an "Operation Not Permitted" message. - 4. Repeat the process by returning to step 1, unless the user presses Ctrl-C (KeyboardInterrupt, SIGINT) or types "exit" when prompted for the filename. -- **Tips**: -
Tip 1: - - Create a reusable function to streamline the code and enhance readability. - -
- -
Tip 2: - - Utilize `os.path.isfile` to verify that the file exists and is not a directory. - -
- -
Tip 3: - - Use the `open` function for file operations. Note that it raises a `PermissionError` when access is denied. Implement try/except blocks to catch this exception and inform the user accordingly. - -
> [!NOTE] From e86f23a45ffe66116b314dbe3194fd4ca4f28785 Mon Sep 17 00:00:00 2001 From: Erkhemee Date: Thu, 23 Jul 2026 19:27:15 +0800 Subject: [PATCH 2/9] Better visuality --- README.md | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 73e2560..d929f2e 100644 --- a/README.md +++ b/README.md @@ -33,16 +33,17 @@ This repository is designed to help Python learners at all levels, starting with ## Project Difficulty Ratings | *Project* | *Category* | *Difficulty* | -| :--- | :--- | :--- | -| **Project name** | ***Beginner** level* | Rating: 0.5 | +| :-- | :-- | :-- | +| ***Beginner** projects* | *Beginner* | ***Rating: 0.5~4.5*** | +| **Project name** | ***Beginner** level* | *Rating: **0.5*** | | [Odd or Even Checker](#28-odd-or-even-checker) | Beginner | 0.5/10 | | [Multiplication Table Generator](#29-multiplication-table-generator) | Beginner | 0.5/10 | | [Simple Interest Calculator](#30-simple-interest-calculator) | Beginner | 0.5/10 | -| **Project name** | ***Beginner** level* | Rating: 1.0 | +| **Project name** | ***Beginner** level* | *Rating: **1.0*** | | [Anagram Checker](#31-anagram-checker) | Beginner | 1.0/10 | | [Acronym Generator](#32-acronym-generator) | Beginner | 1.0/10 | | [Text Reverser](#18-text-reverser) | Beginner | 1.0/10 | -| **Project name** | ***Beginner** level* | Rating: 1.5 | +| **Project name** | ***Beginner** level* | *Rating: **1.5*** | | [Calculator](#1-calculator) | Beginner | 1.5/10 | | [Tip Calculator](#4-tip-calculator) | Beginner | 1.5/10 | | [Temperature Converter](#5-temperature-converter) | Beginner | 1.5/10 | @@ -51,12 +52,12 @@ This repository is designed to help Python learners at all levels, starting with | [Email Slicer](#22-email-slicer) | Beginner | 1.5/10 | | [BMI Calculator](#23-bmi-calculator) | Beginner | 1.5/10 | | [Leap Year Checker](#27-leap-year-checker) | Beginner | 1.5/10 | -| **Project name** | ***Beginner** level* | Rating: 2.0 | +| **Project name** | ***Beginner** level* | *Rating: **2.0*** | | [Number Guessing Game](#2-number-guessing-game) | Beginner | 2.0/10 | | [Word Counter](#7-word-counter) | Beginner | 2.0/10 | | [Mad Libs Generator](#11-mad-libs-generator) | Beginner | 2.0/10 | | [Fibonacci Sequence](#21-fibonacci-sequence) | Beginner | 2.0/10 | -| **Project name** | ***Beginner** level* | Rating: 2.5 | +| **Project name** | ***Beginner** level* | *Rating: **2.5*** | | [Password Generator](#3-password-generator) | Beginner | 2.5/10 | | [Text Encryption](#8-text-encryption) | Beginner | 2.5/10 | | [Countdown Timer](#9-countdown-timer) | Beginner | 2.5/10 | @@ -65,34 +66,34 @@ This repository is designed to help Python learners at all levels, starting with | [Prime Number Generator](#20-prime-number-generator) | Beginner | 2.5/10 | | [Unit Converter](#26-unit-converter) | Beginner | 2.5/10 | | [Currency Converter](#24-currency-converter) | Beginner | 2.5/10 | -| **Project name** | ***Beginner** level* | Rating: 3.0 | +| **Project name** | ***Beginner** level* | *Rating: **3.0*** | | [Pomodoro Timer](#15-pomodoro-timer) | Beginner | 3.0/10 | | [Task Tracker](#25-task-tracker) | Beginner | 3.0/10 | -| **Project name** | ***Beginner** level* | Rating: 3.5 | +| **Project name** | ***Beginner** level* | *Rating: **3.5*** | | [Hangman Game](#13-hangman-game) | Beginner | 3.5/10 | | [File Sorter](#17-file-sorter) | Beginner | 3.5/10 | -| **Project name** | ***Beginner** level* | Rating: 4.0 | +| **Project name** | ***Beginner** level* | *Rating: **4.0*** | | [Address Book](#14-address-book) | Beginner | 4.0/10 | -| **Project name** | ***Beginner** level* | Rating: 4.5 | +| **Project name** | ***Beginner** level* | *Rating: **4.5*** | | [Budget Tracker](#16-budget-tracker) | Beginner | 4.5/10 | | [File viewer](#44-file-viewer) | Beginner | 4.5/10 | -| :--- | :--- | :--- | -| **Project name** | ***Intermediate** level* | Rating: 4.5 | +| ***Intermediate** projects* | *Intermediate* | ***Rating: 4.5~8.5*** | +| **Project name** | ***Intermediate** level* | *Rating: **4.5*** | | [Basic Caesar Cipher](#6-basic-caesar-cipher) | Intermediate | 4.5/10 | | [CSV to JSON Converter](#9-csv-to-json-converter) | Intermediate | 4.5/10 | -| **Project name** | ***Intermediate** level* | Rating: 5.0 | +| **Project name** | ***Intermediate** level* | *Rating: **5.0*** | | [Prime Number Sieve](#5-prime-number-sieve) | Intermediate | 5.0/10 | | [File Metadata Extractor](#8-file-metadata-extractor) | Intermediate | 5.0/10 | -| **Project name** | ***Intermediate** level* | Rating: 5.5 | +| **Project name** | ***Intermediate** level* | *Rating: **5.5*** | | [Bank Account Simulator (OOP)](#7-bank-account-simulator-oop) | Intermediate | 5.5/10 | | [Text-based Adventure Game](#2-text-based-adventure-game) | Intermediate | 5.5/10 | -| **Project name** | ***Intermediate** level* | Rating: 6.0 | +| **Project name** | ***Intermediate** level* | *Rating: **6.0*** | | [Tic Tac Toe](#1-tic-tac-toe) | Intermediate | 6.0/10 | -| **Project name** | ***Intermediate** level* | Rating: 6.5 | +| **Project name** | ***Intermediate** level* | *Rating: **6.5*** | | [Basic Sorting Algorithms](#4-basic-sorting-algorithms) | Intermediate | 6.5/10 | | [Fractal Creator](#10-fractal-creator) | Intermediate | 6.5/10 | | [File Explorer](#11-file-explorer) | Intermediate | 6.5/10 | -| **Project name** | ***Intermediate** level* | Rating: 8.5 | +| **Project name** | ***Intermediate** level* | *Rating: **8.5*** | | [Sudoku Solver](#3-sudoku-solver) | Intermediate | 8.5/10 | ## Beginner Projects From 37cc34d1edc093055a1f3646f527d161b055eff8 Mon Sep 17 00:00:00 2001 From: Erkhemee Date: Thu, 23 Jul 2026 19:30:58 +0800 Subject: [PATCH 3/9] Fixing sooner plz wait --- Intermediate/json_reader.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Intermediate/json_reader.py diff --git a/Intermediate/json_reader.py b/Intermediate/json_reader.py new file mode 100644 index 0000000..45dfa42 --- /dev/null +++ b/Intermediate/json_reader.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 + +import json, os + +def read_json(file): + if not os.path.isfile(file): + print("ERROR: Given location is not file or does not exists") + return + try: + with open(file, encoding='utf-8') as obj: + return json.load(obj) + except json.JSONDecodeError: + print("ERROR: Invaild JSON format") + except Exception as e: + print("ERROR:",e) + +print("Welcome to JSON Reader") +print("Type 'exit' to exit") +print("Current directory:", os.getcwd()) +print("In current directory:") +print(("- " + "\n- ".join(os.listdir())) if os.listdir() else "- No files found!") + +loc = '' +while loc != "exit": + if loc: + dic = read_json(loc) + if not dic: + loc = "" + continue + for n, v in dic.items(): + print("Name:", repr(n), "|", "Value:", repr(v)) + + loc = input("\nEnter path to your JSON to read: ") + From 2a5620a77e03f16ad64f19904e8756a0cc1aea66 Mon Sep 17 00:00:00 2001 From: Erkhemee Date: Thu, 23 Jul 2026 19:33:45 +0800 Subject: [PATCH 4/9] Update and rename json_reader.py to 13_json_reader.py --- Intermediate/{json_reader.py => 13_json_reader.py} | 1 + 1 file changed, 1 insertion(+) rename Intermediate/{json_reader.py => 13_json_reader.py} (97%) diff --git a/Intermediate/json_reader.py b/Intermediate/13_json_reader.py similarity index 97% rename from Intermediate/json_reader.py rename to Intermediate/13_json_reader.py index 45dfa42..8519365 100644 --- a/Intermediate/json_reader.py +++ b/Intermediate/13_json_reader.py @@ -1,4 +1,5 @@ #!/usr/bin/python3 +# Made By @Ericwasepic127 import json, os From 35d3419c6ba8ce7b3ea0007e2ca277777e1bc196 Mon Sep 17 00:00:00 2001 From: Erkhemee Date: Fri, 24 Jul 2026 04:42:27 +0800 Subject: [PATCH 5/9] later will fixed --- main.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..fb5a8f3 --- /dev/null +++ b/main.py @@ -0,0 +1,36 @@ +import os, shutil +sz = shutil.get_terminal_size().columns + +def numput(prompt, default=0, do=int, use=input): + try: + d = do(use(prompt)) + except: + print(f"Non-numeric value - defaulting to {default}") + d = default + return d + +def fnh(ls): + rt = {} + for f in ls: + n, _ = os.path.splitext(f) + c = n.split("_") + v = c[0] + del c[0] + rt[int(v)] = (" ".join(c).title(), f) + +ip = fnh([os.path.join(os.path.join(os.getcwd(), "Intermediate"), z) for z in os.listdir("Intermediate/")]) +bp = fnh([os.path.join(os.path.join(os.getcwd(), "Beginner/"), z) for z in os.listdir("Beginner/")]) +def m(): + print("Welcome to projects browser!") + print("Projects available:") + print("="*sz) + print("\033[1m\033[94mBeginner:") + for q, w in bp.items(): + print(f"#{q}. {w}") + print("-"*sz) + print("\033[1m\033[93mIntermediate:") + for q, w in ip.items(): + print(f"#{q}. {w}") + print("\033[0m="*sz) + + From 8fbd0c26e3c684c351af7d5d9e84bbf32e2d6894 Mon Sep 17 00:00:00 2001 From: Erkhemee Date: Fri, 31 Jul 2026 09:01:49 +0800 Subject: [PATCH 6/9] later fix plz --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index d929f2e..0f4f29b 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple calculator that performs basic arithmetic operations (`+`, `-`, `*`, `/`). - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/1_calculator.py +- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/1_calculator.py) - **Steps**: 1. Prompt the user for two numbers and an operator. @@ -142,6 +143,7 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple random number generator, where users have to submit their guesses as to what the number is. Accept a range within 10 of the random number. `[0 - 100]` - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/2_random_guesser.py +- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/2_random_guesser.py) - **Steps**: 1. Generate a random number within the range `0 - 100`. @@ -178,6 +180,7 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple password generator than can generate custom length passwords, from 8 up to 128 characters. Use uppercase, lowercase, symbols, and numbers. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/3_password_generator.py +- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/3_password_generator.py) - **Steps**: 1. Define your password generator's maps or strings. @@ -214,6 +217,7 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple tip calculator, that calculates the tip based on the total and the desired percentage with splits. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/4_tip_calculator.py +- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/4_tip_calculator.py) - **Steps**: 1. Get the total from the user. @@ -248,6 +252,7 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple temperature converter that converts between Celsius and Fahrenheit. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/5_temperature_converter.py +- [![Live demo](https://img.sheilds.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/5_temperature_converter.py) - **Steps**: 1. Define conversion values for each conversion. @@ -282,6 +287,7 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple palindrome checker. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/6_palindrome_checker.py +- [![Live demo](https://img.sheilds.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/6_palindrome_checker.py) - **Steps**: 1. Prompt the user for a word. @@ -315,6 +321,7 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple word counter. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/7_word_counter.py +- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/7_word_counter.py) - **Steps**: 1. Prompt the user for a file path (TXT). From 6297674d1e427117a7fab6e34d6313afdbf651b7 Mon Sep 17 00:00:00 2001 From: Johan Beytell <107624055+johanbeytell1@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:37:25 +0200 Subject: [PATCH 7/9] Refactor JSON reader with enhanced error handling Refactor JSON reader to improve error handling and code structure. --- Intermediate/13_json_reader.py | 90 +++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 29 deletions(-) diff --git a/Intermediate/13_json_reader.py b/Intermediate/13_json_reader.py index 8519365..ade7257 100644 --- a/Intermediate/13_json_reader.py +++ b/Intermediate/13_json_reader.py @@ -1,35 +1,67 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # Made By @Ericwasepic127 +# JSON Reader - A simple CLI tool to read and pretty-print JSON files -import json, os +import json +import sys +from pathlib import Path +from typing import Any + +def read_json_file(file_path: Path) -> Any | None: + """Read and parse a JSON file.""" + if not file_path.is_file(): + print(f"ERROR: '{file_path}' is not a file or does not exist.", file=sys.stderr) + return None -def read_json(file): - if not os.path.isfile(file): - print("ERROR: Given location is not file or does not exists") - return try: - with open(file, encoding='utf-8') as obj: - return json.load(obj) - except json.JSONDecodeError: - print("ERROR: Invaild JSON format") + with file_path.open(encoding='utf-8') as f: + return json.load(f) + except json.JSONDecodeError as e: + print(f"ERROR: Invalid JSON format in '{file_path}': {e}", file=sys.stderr) except Exception as e: - print("ERROR:",e) - -print("Welcome to JSON Reader") -print("Type 'exit' to exit") -print("Current directory:", os.getcwd()) -print("In current directory:") -print(("- " + "\n- ".join(os.listdir())) if os.listdir() else "- No files found!") - -loc = '' -while loc != "exit": - if loc: - dic = read_json(loc) - if not dic: - loc = "" - continue - for n, v in dic.items(): - print("Name:", repr(n), "|", "Value:", repr(v)) - - loc = input("\nEnter path to your JSON to read: ") + print(f"ERROR: Failed to read '{file_path}': {e}", file=sys.stderr) + return None + +def display_json(data: Any) -> None: + """Display JSON content in a readable format.""" + if isinstance(data, dict): + for key, value in data.items(): + print(f"Name: {key!r} | Value: {value!r}") + elif isinstance(data, list): + for i, item in enumerate(data): + print(f"[{i}]: {item!r}") + else: + # For primitives like string, number, bool + print(data) + +def main() -> None: + print("Welcome to JSON Reader") + print("Type 'exit' to quit\n") + print(f"Current directory: {Path.cwd()}") + + while True: + try: + loc = input("\nEnter path to your JSON file: ").strip() + + if loc.lower() in ("exit", "quit", "q"): + print("Goodbye!") + break + + if not loc: + continue + + json_path = Path(loc).expanduser().resolve() + data = read_json_file(json_path) + + if data is None: + continue + + display_json(data) + + except (KeyboardInterrupt, EOFError): + print("\nGoodbye!") + break + +if __name__ == "__main__": + main() From 2e25b0d4845f9c7fff3f862f369df6856f125add Mon Sep 17 00:00:00 2001 From: Johan Beytell <107624055+johanbeytell1@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:40:08 +0200 Subject: [PATCH 8/9] Delete main.py --- main.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index fb5a8f3..0000000 --- a/main.py +++ /dev/null @@ -1,36 +0,0 @@ -import os, shutil -sz = shutil.get_terminal_size().columns - -def numput(prompt, default=0, do=int, use=input): - try: - d = do(use(prompt)) - except: - print(f"Non-numeric value - defaulting to {default}") - d = default - return d - -def fnh(ls): - rt = {} - for f in ls: - n, _ = os.path.splitext(f) - c = n.split("_") - v = c[0] - del c[0] - rt[int(v)] = (" ".join(c).title(), f) - -ip = fnh([os.path.join(os.path.join(os.getcwd(), "Intermediate"), z) for z in os.listdir("Intermediate/")]) -bp = fnh([os.path.join(os.path.join(os.getcwd(), "Beginner/"), z) for z in os.listdir("Beginner/")]) -def m(): - print("Welcome to projects browser!") - print("Projects available:") - print("="*sz) - print("\033[1m\033[94mBeginner:") - for q, w in bp.items(): - print(f"#{q}. {w}") - print("-"*sz) - print("\033[1m\033[93mIntermediate:") - for q, w in ip.items(): - print(f"#{q}. {w}") - print("\033[0m="*sz) - - From 942b55d7284b2e1dd49d511d1683fb11920e2395 Mon Sep 17 00:00:00 2001 From: Johan Beytell <107624055+johanbeytell1@users.noreply.github.com> Date: Wed, 5 Aug 2026 11:49:11 +0200 Subject: [PATCH 9/9] Update project counts and correct typos in README Updated project counts and fixed typos in the README. --- README.md | 177 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 93 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index 0f4f29b..ace0bc0 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ An open-source GitHub repository containing Python project ideas, steps, tips, a This repository is designed to help Python learners at all levels, starting with beginner-friendly projects and gradually progressing to more advanced ones. Each project includes clear instructions and a working code implementation. -**Total Projects:** 44 +**Total Projects:** 45 --- -**Total Beginner Projects:** 33 +**Total Beginner Projects:** 32 -**Total Intermediate Projects:** 11 +**Total Intermediate Projects:** 13 ## Table of Contents @@ -21,7 +21,7 @@ This repository is designed to help Python learners at all levels, starting with ## Setup -- Ensure have at least Python `3.6` or later (we recommend `3.12` or later) installed on your computer. You can do a quick search and download it from a trusted provider for your platform. +- Ensure you have at least Python `3.6` or later (we recommend `3.12` or later) installed on your computer. You can do a quick search and download it from a trusted provider for your platform. - Ensure you have an IDE or a place where you can code and run the Python interpreter. @@ -32,69 +32,54 @@ This repository is designed to help Python learners at all levels, starting with ## Project Difficulty Ratings -| *Project* | *Category* | *Difficulty* | -| :-- | :-- | :-- | -| ***Beginner** projects* | *Beginner* | ***Rating: 0.5~4.5*** | -| **Project name** | ***Beginner** level* | *Rating: **0.5*** | -| [Odd or Even Checker](#28-odd-or-even-checker) | Beginner | 0.5/10 | -| [Multiplication Table Generator](#29-multiplication-table-generator) | Beginner | 0.5/10 | -| [Simple Interest Calculator](#30-simple-interest-calculator) | Beginner | 0.5/10 | -| **Project name** | ***Beginner** level* | *Rating: **1.0*** | -| [Anagram Checker](#31-anagram-checker) | Beginner | 1.0/10 | -| [Acronym Generator](#32-acronym-generator) | Beginner | 1.0/10 | -| [Text Reverser](#18-text-reverser) | Beginner | 1.0/10 | -| **Project name** | ***Beginner** level* | *Rating: **1.5*** | +| Project | Category | Difficulty | +| :--- | :--- | :--- | | [Calculator](#1-calculator) | Beginner | 1.5/10 | +| [Number Guessing Game](#2-number-guessing-game) | Beginner | 2.0/10 | +| [Password Generator](#3-password-generator) | Beginner | 2.5/10 | | [Tip Calculator](#4-tip-calculator) | Beginner | 1.5/10 | | [Temperature Converter](#5-temperature-converter) | Beginner | 1.5/10 | | [Palindrome Checker](#6-palindrome-checker) | Beginner | 1.5/10 | -| [Dice Rolling Simulator](#12-dice-rolling-simulator) | Beginner | 1.5/10 | -| [Email Slicer](#22-email-slicer) | Beginner | 1.5/10 | -| [BMI Calculator](#23-bmi-calculator) | Beginner | 1.5/10 | -| [Leap Year Checker](#27-leap-year-checker) | Beginner | 1.5/10 | -| **Project name** | ***Beginner** level* | *Rating: **2.0*** | -| [Number Guessing Game](#2-number-guessing-game) | Beginner | 2.0/10 | | [Word Counter](#7-word-counter) | Beginner | 2.0/10 | -| [Mad Libs Generator](#11-mad-libs-generator) | Beginner | 2.0/10 | -| [Fibonacci Sequence](#21-fibonacci-sequence) | Beginner | 2.0/10 | -| **Project name** | ***Beginner** level* | *Rating: **2.5*** | -| [Password Generator](#3-password-generator) | Beginner | 2.5/10 | | [Text Encryption](#8-text-encryption) | Beginner | 2.5/10 | | [Countdown Timer](#9-countdown-timer) | Beginner | 2.5/10 | | [Rock Paper Scissors](#10-rock-paper-scissors) | Beginner | 2.5/10 | +| [Mad Libs Generator](#11-mad-libs-generator) | Beginner | 2.0/10 | +| [Dice Rolling Simulator](#12-dice-rolling-simulator) | Beginner | 1.5/10 | +| [Hangman Game](#13-hangman-game) | Beginner | 3.5/10 | +| [Address Book](#14-address-book) | Beginner | 4.0/10 | +| [Pomodoro Timer](#15-pomodoro-timer) | Beginner | 3.0/10 | +| [Budget Tracker](#16-budget-tracker) | Beginner | 4.5/10 | +| [File Sorter](#17-file-sorter) | Beginner | 3.5/10 | +| [Text Reverser](#18-text-reverser) | Beginner | 1.0/10 | | [Simple Quiz Game](#19-simple-quiz-game) | Beginner | 2.5/10 | | [Prime Number Generator](#20-prime-number-generator) | Beginner | 2.5/10 | -| [Unit Converter](#26-unit-converter) | Beginner | 2.5/10 | +| [Fibonacci Sequence](#21-fibonacci-sequence) | Beginner | 2.0/10 | +| [Email Slicer](#22-email-slicer) | Beginner | 1.5/10 | +| [BMI Calculator](#23-bmi-calculator) | Beginner | 1.5/10 | | [Currency Converter](#24-currency-converter) | Beginner | 2.5/10 | -| **Project name** | ***Beginner** level* | *Rating: **3.0*** | -| [Pomodoro Timer](#15-pomodoro-timer) | Beginner | 3.0/10 | | [Task Tracker](#25-task-tracker) | Beginner | 3.0/10 | -| **Project name** | ***Beginner** level* | *Rating: **3.5*** | -| [Hangman Game](#13-hangman-game) | Beginner | 3.5/10 | -| [File Sorter](#17-file-sorter) | Beginner | 3.5/10 | -| **Project name** | ***Beginner** level* | *Rating: **4.0*** | -| [Address Book](#14-address-book) | Beginner | 4.0/10 | -| **Project name** | ***Beginner** level* | *Rating: **4.5*** | -| [Budget Tracker](#16-budget-tracker) | Beginner | 4.5/10 | -| [File viewer](#44-file-viewer) | Beginner | 4.5/10 | -| ***Intermediate** projects* | *Intermediate* | ***Rating: 4.5~8.5*** | -| **Project name** | ***Intermediate** level* | *Rating: **4.5*** | -| [Basic Caesar Cipher](#6-basic-caesar-cipher) | Intermediate | 4.5/10 | -| [CSV to JSON Converter](#9-csv-to-json-converter) | Intermediate | 4.5/10 | -| **Project name** | ***Intermediate** level* | *Rating: **5.0*** | -| [Prime Number Sieve](#5-prime-number-sieve) | Intermediate | 5.0/10 | -| [File Metadata Extractor](#8-file-metadata-extractor) | Intermediate | 5.0/10 | -| **Project name** | ***Intermediate** level* | *Rating: **5.5*** | -| [Bank Account Simulator (OOP)](#7-bank-account-simulator-oop) | Intermediate | 5.5/10 | -| [Text-based Adventure Game](#2-text-based-adventure-game) | Intermediate | 5.5/10 | -| **Project name** | ***Intermediate** level* | *Rating: **6.0*** | +| [Unit Converter](#26-unit-converter) | Beginner | 2.5/10 | +| [Leap Year Checker](#27-leap-year-checker) | Beginner | 1.5/10 | +| [Odd or Even Checker](#28-odd-or-even-checker) | Beginner | 0.5/10 | +| [Multiplication Table Generator](#29-multiplication-table-generator) | Beginner | 0.5/10 | +| [Simple Interest Calculator](#30-simple-interest-calculator) | Beginner | 0.5/10 | +| [Anagram Checker](#31-anagram-checker) | Beginner | 1.0/10 | +| [Acronym Generator](#32-acronym-generator) | Beginner | 1.0/10 | | [Tic Tac Toe](#1-tic-tac-toe) | Intermediate | 6.0/10 | -| **Project name** | ***Intermediate** level* | *Rating: **6.5*** | +| [Text-based Adventure Game](#2-text-based-adventure-game) | Intermediate | 5.5/10 | +| [Sudoku Solver](#3-sudoku-solver) | Intermediate | 8.5/10 | | [Basic Sorting Algorithms](#4-basic-sorting-algorithms) | Intermediate | 6.5/10 | +| [Prime Number Sieve](#5-prime-number-sieve) | Intermediate | 5.0/10 | +| [Basic Caesar Cipher](#6-basic-caesar-cipher) | Intermediate | 4.5/10 | +| [Bank Account Simulator (OOP)](#7-bank-account-simulator-oop) | Intermediate | 5.5/10 | +| [File Metadata Extractor](#8-file-metadata-extractor) | Intermediate | 5.0/10 | +| [CSV to JSON Converter](#9-csv-to-json-converter) | Intermediate | 4.5/10 | | [Fractal Creator](#10-fractal-creator) | Intermediate | 6.5/10 | | [File Explorer](#11-file-explorer) | Intermediate | 6.5/10 | -| **Project name** | ***Intermediate** level* | *Rating: **8.5*** | -| [Sudoku Solver](#3-sudoku-solver) | Intermediate | 8.5/10 | +| [File Viewer](#12-file-viewer) | Intermediate | 4.5/10 | +| [JSON Reader](#13-json-reader) | Intermediate | 5/10 | + ## Beginner Projects @@ -107,7 +92,6 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple calculator that performs basic arithmetic operations (`+`, `-`, `*`, `/`). - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/1_calculator.py -- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/1_calculator.py) - **Steps**: 1. Prompt the user for two numbers and an operator. @@ -143,7 +127,6 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple random number generator, where users have to submit their guesses as to what the number is. Accept a range within 10 of the random number. `[0 - 100]` - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/2_random_guesser.py -- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/2_random_guesser.py) - **Steps**: 1. Generate a random number within the range `0 - 100`. @@ -180,7 +163,6 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple password generator than can generate custom length passwords, from 8 up to 128 characters. Use uppercase, lowercase, symbols, and numbers. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/3_password_generator.py -- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/3_password_generator.py) - **Steps**: 1. Define your password generator's maps or strings. @@ -217,7 +199,6 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple tip calculator, that calculates the tip based on the total and the desired percentage with splits. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/4_tip_calculator.py -- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/4_tip_calculator.py) - **Steps**: 1. Get the total from the user. @@ -252,7 +233,6 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple temperature converter that converts between Celsius and Fahrenheit. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/5_temperature_converter.py -- [![Live demo](https://img.sheilds.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/5_temperature_converter.py) - **Steps**: 1. Define conversion values for each conversion. @@ -287,7 +267,6 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple palindrome checker. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/6_palindrome_checker.py -- [![Live demo](https://img.sheilds.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/6_palindrome_checker.py) - **Steps**: 1. Prompt the user for a word. @@ -321,7 +300,6 @@ These projects are ideal for those new to Python. Each project includes a descri - **Description**: Build a simple word counter. - **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/7_word_counter.py -- [![Live demo](https://img.shields.io/badge/Live_code_running-SUPY3IDE-green)](https://ericwasepic127.github.io/ide.html?url=https://raw.githubusercontent.com/Infinitode/Python-projects/refs/heads/main/Beginner/7_word_counter.py) - **Steps**: 1. Prompt the user for a file path (TXT). @@ -1115,32 +1093,6 @@ These projects are ideal for those new to Python. Each project includes a descri -### 44. File viewer -- **Difficulty**: 4.5/10 -- **Description**: Get filename from user, and print user's file contents. Avoid any crashes! Don't forget it must be infinte loop -- **Solution**: https://github.com/Infinitode/Python-Projects/blob/main/Beginner/44_file_viewer.py - [Original](https://github.com/Ericwasepic127/Python-Projects/blob/main/Beginner/44_file_viewer.py) -- **Steps**: - 1. Ask for filename - 2. Check does file exists: If doesn't exists, show user as File Not Found. Handle it for directories too - 3. Read the file. If it encourtes permission error, notify user as operation not permitted - 4. Repeat back to 1, unless user clicks Ctrl-C (KeyboardInterrupt, SIGINT) or type `exit` at filename section -- **Tips:**: -
Tip 1: - - Make reusable function for it so it makes easier - -
-
Tip 2: - - Use `os.path.isfile` to check your file exists and it's not directory - -
-
Tip 3: - - Use `open` to handle file operation. It raises exception `PermissionError` when permission failed. Use `try/except` to catch and show user as operation not permitted - -
- > [!NOTE] > Working code solutions are in the `/Beginner` folder. @@ -1446,6 +1398,63 @@ These projects are ideal for those with experience in Python. Each project inclu `os.path.isfile` determines whether it file or not; if it is a file, it returns `True`; if not, return `False`. + +### 12. File viewer +- **Difficulty**: 4.5/10 +- **Description**: Prompt the user for a filename and print the contents of the specified file. Ensure the program handles errors gracefully to avoid crashes. The program should run in an infinite loop until the user decides to exit. +- **Solution**: [GitHub Repository](https://github.com/Infinitode/Python-Projects/blob/main/Intermediate/12_file_viewer.py) - [Original Source](https://github.com/Ericwasepic127/Python-Projects/blob/main/Beginner/44_file_viewer.py) +- **Steps**: + 1. Prompt the user for a filename. + 2. Check if the file exists: If it does not exist, inform the user with a "File Not Found" message. Ensure to check for directories as well. + 3. Attempt to read the file. If a permission error occurs, notify the user with an "Operation Not Permitted" message. + 4. Repeat the process by returning to step 1, unless the user presses Ctrl-C (KeyboardInterrupt, SIGINT) or types "exit" when prompted for the filename. +- **Tips**: +
Tip 1: + + Create a reusable function to streamline the code and enhance readability. + +
+ +
Tip 2: + + Utilize `os.path.isfile` to verify that the file exists and is not a directory. + +
+ +
Tip 3: + + Use the `open` function for file operations. Note that it raises a `PermissionError` when access is denied. Implement try/except blocks to catch this exception and inform the user accordingly. + +
+ +### 13. JSON Reader +- **Difficulty**: 5/10 +- **Description**: Prompt the user for a JSON filename and print the contents of the specified file in a readable key-value format. Ensure the program handles errors gracefully to avoid crashes. The program should run in an infinite loop until the user decides to exit. +- **Solution**: [GitHub Repository](https://github.com/Infinitode/Python-Projects/blob/main/Intermediate/13_json_viewer.py) - Original version by [Ericwasepic127](https://github.com/Ericwasepic127/Python-Projects/). +- **Steps**: + 1. Prompt the user for a filename. + 2. Check if the file exists and is a file: If it does not exist, inform the user with a "File Not Found" message. Ensure to check for directories as well. + 3. Attempt to read and parse the file as JSON. If the JSON is invalid, notify the user with an "Invalid JSON Format" message. If a permission error occurs, notify the user with an "Operation Not Permitted" message. + 4. If parsing is successful, iterate through the data: If it's a dictionary, print each Name and Value pair. If it's a list, print each item with its index. + 5. Repeat the process by returning to step 1, unless the user presses Ctrl-C (KeyboardInterrupt, SIGINT) or types "exit" when prompted for the filename. +- **Tips**: +
Tip 1: + + Create a reusable function `read_json()` to handle file validation and JSON parsing separately to streamline the code and enhance readability. + +
+ +
Tip 2: + + Utilize `os.path.isfile` to verify that the file exists and is not a directory, and use `json.load()` inside a try/except block to catch `json.JSONDecodeError`. + +
+ +
Tip 3: + + Use `repr()` or `!r` formatting when printing keys and values to preserve data types, and check if the loaded JSON is a dict before calling `.items()` to support lists as well. + +
> [!NOTE]