Skip to content

butunghd0-max/python-learning-type-shyt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Learning Projects

A structured collection of Python console applications and scripts developed to build programming fundamentals. The repository progresses from basic logic and calculations to external API integrations, data serialization, and mathematical simulations. This project is part of Creativity, Activity and Service (CAS).

Most of these projects come from things I actually use or think about: robotics, 3D printing, anime, and engineering math. Nothing here was built from a tutorial. Each project started as a question like "how does PID tuning actually work?" or "how much does a gacha banner really cost?" and turned into working code.

Note: This repository covers work from July 2025 to January 2026 and is no longer being updated. Newer Python projects are published as individual repositories.


Table of Contents


Repository Structure

The projects are organized by complexity into two main categories.

1. Beginner Projects

Focused on basic I/O, control flow, loops, mathematical operations, and simple file handling.

Project Description Script
3D Print Time and Cost Estimator Calculates mass, cost, and estimated print time based on filament parameters and print speed. print_estimator.py
Anime and Manga Watchlist A CLI tracker that saves, loads, and updates viewing progress using a local JSON file. watchlist_tracker.py
Engineering Calculator Performs electrical (Ohm's Law, power), mechanical (kinetic energy), and geometry calculations with unit conversion. engineering_calculator.py
Gacha Pull Simulator Simulates pull probabilities with optional pity systems and tracks estimated costs until a target drop is achieved. gacha_simulator.py
Gear Ratio and Speed Estimator Calculates gear ratios, simplifies them to integer form, computes output RPM, and analyzes torque vs. speed trade-offs. gear_ratio_estimator.py
Reading Pacer Calculates required daily reading goals (pages or chapters) to meet a specific date deadline. reading_pacer.py
Servo Duty Cycle Converter Converts target servo angles into hardware-friendly PWM duty cycles and optional timer register counts. servo_duty_cycle_converter.py

2. Intermediate Projects

Introduces external HTTP requests, data caching, data visualization, and domain-specific file formatting.

Project Description Script
Basic PID Controller Simulation A discrete-time PID loop simulation that models a first-order plant and plots process variables, control signals, and error curves using matplotlib. pid_simulation.py
G-Code Toolpath Generator Converts a sequence of 2D XY coordinates into a formatted .gcode file with configurable travel rates, feed rates, and nozzle temperature. gcode_generator.py
Random Anime Quote API Fetcher Fetches quotes from multiple public APIs with automatic provider fallback, exponential backoff retries, and a local JSON cache. quote_fetcher.py

Concepts Applied

Across these projects, the following Python concepts and libraries are used:

Core Python

  • Variables, loops, conditionals, string formatting, and the math module.
  • dataclasses for clean state modeling (PID controller, servo specs).
  • argparse for CLI argument parsing with defaults, types, and help text.
  • fractions.Fraction for exact integer-ratio simplification.

Data Structures

  • Lists, dictionaries, sets, and tuples.
  • Type aliases (Point = Tuple[float, float]).

File I/O and Serialization

  • Reading and writing JSON files with json.
  • Managing file paths with pathlib.Path.
  • Writing domain-specific output formats (.gcode).

Networking

  • Making HTTP requests with requests.
  • Parsing JSON API responses with nested object handling.
  • Handling timeouts, connection errors, and HTTP status codes.
  • Retry logic with exponential backoff.
  • Browser-like header spoofing for restrictive endpoints.

Data Visualization

  • Multi-subplot figure layout with matplotlib.pyplot.
  • Plotting system responses with labeled axes, legends, and grid overlays.

Engineering and Math

  • Ohm's Law and power calculations.
  • Kinetic energy formula.
  • Cylinder volume with unit conversion.
  • PWM duty cycle derivation from pulse width and frequency.
  • Linear interpolation for servo angle mapping.
  • PID control with anti-windup integral clamping and derivative initialization.
  • Gear ratio computation and system analysis (torque vs. speed classification).
  • Probability simulation and statistical analysis (mean, median, min, max).

How to Run

Make sure Python 3.10+ is installed.

  1. Clone the repository:
git clone https://github.com/butunghd0-max/python-learning-type-shyt.git
  1. Navigate to the specific project folder you want to run.

  2. If a requirements.txt exists in the folder, install the dependencies:

python -m pip install -r requirements.txt
  1. Run the script:
python script_name.py

Replace script_name.py with the actual filename, for example gacha_simulator.py.


Project Details

Quick usage examples for each project. Every project includes input validation, so you can expect clear error messages if you type something wrong.

3D Print Time and Cost Estimator

Estimates how long a print will take, how much filament it uses, and what that costs. Uses PLA density and filament diameter constants for the calculation.

python print_estimator.py

Anime and Manga Watchlist

Add, update, view, and delete entries in a local watchlist.json file. Includes a formatted table view and duplicate title detection.

python watchlist_tracker.py

Engineering Calculator

Three modes in one: electrical (power, current, voltage, resistance), mechanical (kinetic energy), and geometry (cylinder volume with unit conversion between m, cm, mm, in, ft).

python engineering_calculator.py

Gacha Pull Simulator

Two modes: a single dramatic pull, or a batch of thousands of trials to get real probability averages. Supports optional pity limits that cap the number of pulls.

python gacha_simulator.py

Gear Ratio and Speed Estimator

Enter the teeth count on two gears and a motor RPM. Outputs the gear ratio in both decimal and simplified integer form, the output RPM, and whether the setup favors torque, speed, or is a 1:1 direct drive.

python gear_ratio_estimator.py

Reading Pacer

Tell it what you are reading, how far you are, and your deadline. It calculates how many pages or chapters per day you need to finish on time. Handles edge cases like past deadlines and already-finished books.

python reading_pacer.py

Servo Duty Cycle Converter

Converts an angle to a pulse width in milliseconds, then to a duty cycle percentage. Supports custom servo specs (min/max angle, min/max pulse, frequency) and optional PWM timer resolution for embedded use.

python servo_duty_cycle_converter.py 90
python servo_duty_cycle_converter.py 37.5 --resolution-bits 10
python servo_duty_cycle_converter.py 120 --frequency 50 --min-pulse-ms 0.9 --max-pulse-ms 2.1 --resolution-bits 12

Example output:

Angle: 90.00 deg
Pulse width: 1.5000 ms
Duty cycle: 7.5000 %
PWM period: 20.0000 ms (50.00 Hz)
Counts (10-bit): 77 / 1023

Basic PID Controller Simulation

Simulates a PID controller driving a first-order plant. Reports overshoot percentage, settling time (2% band), and steady-state error. Plots three subplots: process variable vs. setpoint, control signal, and error over time.

python pid_simulation.py
python pid_simulation.py --kp 2.5 --ki 1.0 --kd 0.6
python pid_simulation.py --no-plot

Tuning guide:

  1. Start with Ki=0 and Kd=0. Increase Kp until the response is fast but not unstable.
  2. Add small Kd to reduce overshoot and oscillation.
  3. Add Ki to remove steady-state error.
  4. If oscillation grows over time, reduce Ki or widen the integral limits in code.

Requires matplotlib:

python -m pip install -r requirements.txt

G-Code Toolpath Generator

Takes a list of XY points and produces a valid .gcode file with homing, absolute positioning, millimeter units, and optional nozzle temperature control. Results should be verified in a G-code viewer before running on real hardware.

python gcode_generator.py
python gcode_generator.py --output square_50mm.gcode --points "10,10 10,50 50,50 50,10 10,10" --feedrate-linear 1500 --nozzle-temp 200

Random Anime Quote API Fetcher

Tries Yurippe first, falls back to Animechan, and if both fail, pulls a random quote from the local cache. The cache is built automatically over time and deduplicates entries. Each quote shows the source it came from.

python quote_fetcher.py

Example output:

"Believe in the me that believes in you!" - Kamina (Gurren Lagann) [yurippe]

Requires requests:

python -m pip install -r requirements.txt

References

"Animechan API." Animechan, Animechan Contributors, api.animechan.io. Accessed 12 Nov. 2025.

Astrom, Karl Johan, and Richard M. Murray. Feedback Systems: An Introduction for Scientists and Engineers. 2nd ed., Princeton University Press, 2021.

"G-code." RepRap Wiki, RepRap Contributors, reprap.org/wiki/G-code. Accessed 8 Oct. 2025.

Hunter, John D. "Matplotlib: A 2D Graphics Environment." Computing in Science and Engineering, vol. 9, no. 3, 2007, pp. 90-95. matplotlib.org. Accessed 14 Sept. 2025.

The Matplotlib Development Team. "matplotlib.pyplot." Matplotlib 3.8 Documentation, matplotlib.org/stable/api/pyplot_summary.html. Accessed 14 Sept. 2025.

The Matplotlib Development Team. "matplotlib.pyplot.subplots." Matplotlib 3.8 Documentation, matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html. Accessed 15 Sept. 2025.

Nise, Norman S. Control Systems Engineering. 8th ed., Wiley, 2019.

Python Software Foundation. "argparse -- Parser for Command-Line Options, Arguments and Sub-Commands." Python 3.12 Documentation, docs.python.org/3/library/argparse.html. Accessed 19 Aug. 2025.

Python Software Foundation. "dataclasses -- Data Classes." Python 3.12 Documentation, docs.python.org/3/library/dataclasses.html. Accessed 19 Aug. 2025.

Python Software Foundation. "datetime -- Basic Date and Time Types." Python 3.12 Documentation, docs.python.org/3/library/datetime.html. Accessed 5 Aug. 2025.

Python Software Foundation. "fractions -- Rational Numbers." Python 3.12 Documentation, docs.python.org/3/library/fractions.html. Accessed 22 July 2025.

Python Software Foundation. "json -- JSON Encoder and Decoder." Python 3.12 Documentation, docs.python.org/3/library/json.html. Accessed 28 July 2025.

Python Software Foundation. "math -- Mathematical Functions." Python 3.12 Documentation, docs.python.org/3/library/math.html. Accessed 17 July 2025.

Python Software Foundation. "pathlib -- Object-Oriented Filesystem Paths." Python 3.12 Documentation, docs.python.org/3/library/pathlib.html. Accessed 28 July 2025.

Python Software Foundation. "The Python Standard Library." Python 3.12 Documentation, docs.python.org/3/library/. Accessed 17 July 2025.

Python Software Foundation. "statistics -- Mathematical Statistics Functions." Python 3.12 Documentation, docs.python.org/3/library/statistics.html. Accessed 12 Aug. 2025.

Reitz, Kenneth. "Requests: HTTP for Humans." Requests 2.31 Documentation, docs.python-requests.org/en/latest/. Accessed 3 Nov. 2025.

"Yurippe Anime Quotes API." Yurippe, yurippe.vercel.app. Accessed 12 Nov. 2025.


License

This is a personal learning repository. Code is open for reference and educational use.

About

A progressive collection/compilation of Python console applications, ranging from basic engineering calculators to API integrations and PID control simulations. From Jul 17, 2025 - Jan 08, 2026, wont be updating this anymore so any new will be individual repo (just like the java learning).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages