Skip to content

Shotza247/Introduction_into_Python

Repository files navigation

Starting Into Python

A collection of my first Python programs, built from scratch — starting on a mobile phone before moving to a full machine. These cover the core fundamentals of Python: input handling, string manipulation, arithmetic, loops, lists, dictionaries, and object-oriented programming.

I came in with a C# background, which gave me a head start on logic and structure. The focus here was learning Python's syntax, conventions, and built-in capabilities as quickly as possible through hands-on experimentation.

Mobile app used for early learning: Python Coding
IDE / Runtime: Python 3


Table of Contents


Project Overview

graph TD
    A[Python Foundations] --> B[Input & Output]
    A --> C[String Manipulation]
    A --> D[Arithmetic]
    A --> E[Control Flow]
    A --> F[Data Structures]
    A --> G[Object-Oriented Programming]

    E --> E1[if / elif / else]
    E --> E2[while loops]
    E --> E3[for loops with range]

    F --> F1[Lists]
    F --> F2[Dictionaries]
    F --> F3[List of Dictionaries]

    G --> G1[Classes and __init__]
    G --> G2[Instance Methods]
    G --> G3[Tax Bracket Logic]

    F1 --> F1a[lstdatatables.py]
    F3 --> F3a[addDicts2List.py]
    G1 --> G1a[Class1Employees.ipynb]
Loading

Programs


1. PrintInput.py

The first program written — collects a user's name and age, greets them, and classifies their life stage. Includes exception handling for invalid input.

Concepts: input(), string concatenation, int() type conversion, if/elif/else, try/except

Enter your first name: Romeo
Enter your last name: Ndlovu
Hello Romeo Ndlovu, welcome to the Python world.
Please enter your age: 24
Your at an adolescent age.

Age classification logic:

Age Range Category
13 – 17 Teen
18 – 25 Adolescent
26 – 31 Peak young adult
32 – 50 Middle aged adult
51+ Retirement range

2. stringMethods.py

Explores Python's built-in string methods against a fixed course string.

Concepts: .upper(), .lower(), .find(), .replace(), .split(), in operator, user search input

course = "Python for beginners"
Method Output
.upper() PYTHON FOR BEGINNERS
.lower() python for beginners
.find("n") 5 (first index of "n")
.replace("for", "by") Python by beginners

3. simpleMaths.py

Demonstrates Python's arithmetic operators and how operator precedence works in compound expressions.

Concepts: +, -, *, /, BODMAS / operator precedence

x = (10 - 5) + 3 * 10 / 2
# Evaluates as: 5 + 15.0 = 20.0

4. range.py

Uses a for loop with range(start, stop, step) to print a growing pattern of asterisks.

Concepts: for loop, range(), step parameter, string repetition with *

for number in range(5, 20, 2):
    print(number * "*")
*****
*******
*********
...

5. whileloopPyramid.py

Creates a two-sided shape using two back-to-back while loops — one ascending, one descending.

Concepts: while loop, increment/decrement, loop direction control

#
##
###
...
##########
@@@@@@@@@@
@@@@@@@@@
...
@

6. Listvalues.py

Demonstrates the core list operations Python provides — adding, inserting, removing, searching, and iterating.

Concepts: list[], .append(), .insert(), .remove(), in operator, while loop iteration, len()

lstname = ["John", "Sammy", "Sarah", "Linda"]

⚠️ Bug noted: lstname.find(searchname) on line 33 will raise an AttributeError — Python lists do not have a .find() method. That method belongs to strings. The correct list equivalent is lstname.index(searchname).

Fix:

# ❌ Before
print(str(lstname.find(searchname)))

# ✅ After
if searchname in lstname:
    print(str(lstname.index(searchname)))

7. lstdatatables.py

The most layered program in the fundamentals section. Manages a pre-populated employee table using parallel lists, calculates tax deductions via a tiered function, then loops to allow the user to add new employees at runtime.

Concepts: multiple parallel lists, functions, tiered conditional logic, while loops, insert(), append(), dynamic data growth

Data Flow Diagram

flowchart TD
    A[Program Start] --> B[Initialise parallel lists\nlstnames, lstdept, lstsalary, lstid, lsttaxdeduction]
    B --> C[while icount is less than len of lstnames]
    C --> D[lstid.insert at icount]
    D --> E[Call taxrates with icount and salary]

    subgraph taxrates Function
        E --> F{Salary bracket check}
        F -->|<= 10000| G[taxrate = 8.5%]
        F -->|10001 to 14999| H[taxrate = 11%]
        F -->|15000 and above| I[taxrate = 15%]
        G & H & I --> J[taxvalue = taxrate x salary]
        J --> K[lsttaxdeduction.insert at num index]
    end

    K --> L[Print employee row:\nID, Name, Dept, Salary, Tax]
    L --> M[icount plus plus]
    M -->|loop| C
    C -->|done| N[Prompt: Add new user? Yes/No]

    subgraph Append Loop
        N -->|YES| O[Input name, dept, salary]
        O --> P[Append to all lists]
        P --> Q[Call taxrates for new entry]
        Q --> N
        N -->|NO| R[Print all lists]
    end
Loading

Pre-loaded Employee Data

ID Name Department Salary Tax Rate
0 Sarah HR R12,456 15%
1 Mike Finance R16,500 15%
2 Thabo Sales R9,567 8.5%
3 Palesa Marketing R9,863 8.5%
4 Mlu ICT R10,345 11%
5 Thandiwe Sales R10,000 11%

8. dictionaries(kvpairs).py

Introduces Python dictionaries as a key-value store and demonstrates accessing keys and values separately.

Concepts: dict{}, .keys(), .values(), key-value pairs

tinydict = {
    "empid": 100,
    "name": "john",
    "paycode": 6734,
    "dept": "sales",
    "salary": 16_250,
    "monthly tax": 3_650
}

Note: Python allows underscores in numeric literals (16_250) for readability — they have no effect on the value.


9. addDicts2List.py

Combines lists and dictionaries — each element in the list is a full dictionary record, allowing structured multi-field data to be stored and iterated cleanly.

Concepts: list of dicts, .append() with dict literal, while loop, .keys(), .values()

Structure Diagram

graph TD
    L["dict  list"]
    L --> D1["dict index 0"]
    L --> D2["dict index 1"]

    D1 --> K1[empid: 100]
    D1 --> K2[name: john]
    D1 --> K3[paycode: 6734]
    D1 --> K4[dept: sales]
    D1 --> K5[salary: 16250]
    D1 --> K6[monthly tax: 3650]

    D2 --> K7[empid: 101]
    D2 --> K8[name: Ben]
    D2 --> K9[paycode: 4332]
    D2 --> K10[dept: marketing]
    D2 --> K11[salary: 10000]
    D2 --> K12[monthly tax: 1230]
Loading

Note: naming the list variable dict shadows Python's built-in dict type. Renaming it to employees or records is the safe convention.


10. StatisticalCalculations.py

Applies Python's standard library and manual index calculations to derive descriptive statistics from a 40-point dataset.

Concepts: sorted(), sum(), len(), manual median formula, statistics.mode, f-strings

data = [12, 18, 14, 20, 16, 22, 8, 24, 11, 13, ...]  # 40 values
Statistic Result
Minimum 7
Maximum 30
Range 23
Mean ~16.5
Median ~16.5
Mode 15

11. ClassesAndMethods / Class1Employees.ipynb

The most structurally complex program in the repository — introduces object-oriented programming by defining an Employee class with instance attributes and two methods: one for full name formatting and one for tiered tax calculation.

Concepts: class, __init__, self, instance attributes, instance methods, tax bracket logic, Jupyter Notebook

Class Structure

classDiagram
    class Employee {
        +string Firstname
        +string Lastname
        +string Email
        +int Salary
        +__init__(first, last, pay)
        +fullname() string
        +taxdeduction(pay) float
    }
Loading

Object Instantiation and Method Flow

flowchart TD
    A[User Input:\nfirst, last, pay] --> B[Employee.__init__]

    subgraph __init__ Constructor
        B --> C[self.Firstname = first]
        B --> D[self.Lastname = last]
        B --> E["self.Email = first + '.' + last + '@Java.com'"]
        B --> F[self.Salary = pay]
    end

    C & D & E & F --> G[emp object created]

    G --> H[Call emp.taxdeduction with emp.Salary]

    subgraph taxdeduction Method
        H --> I{Salary bracket}
        I -->|pay <= 10000| J[8.7% rate]
        I -->|10001 to 25000| K[11.5% rate]
        I -->|25001 to 40000| L[13.5% rate]
        I -->|above 40000| M[15.7% rate]
        J & K & L & M --> N[Return pay x rate]
    end

    N --> O[Print tax deduction amount]
Loading

Tax Bracket Reference

Salary Range Tax Rate Example (R22,000)
Up to R10,000 8.7%
R10,001 – R25,000 11.5% R2,530
R25,001 – R40,000 13.5%
Above R40,000 15.7%

Known Issues

File Issue Fix
Listvalues.py lstname.find() does not exist on lists — this is a string method and will raise AttributeError at runtime Replace with lstname.index(searchname) inside the if searchname in lstname check
addDicts2List.py Variable named dict shadows Python's built-in dict type Rename to employees or records

Concepts Covered

Concept Files
User input and output PrintInput.py
String methods stringMethods.py
Arithmetic and operator precedence simpleMaths.py
For loops and range range.py
While loops whileloopPyramid.py, lstdatatables.py
List operations Listvalues.py, lstdatatables.py
Functions and parameters lstdatatables.py
Tiered conditional logic lstdatatables.py, Class1Employees.ipynb
Dictionaries dictionaries(kvpairs).py, addDicts2List.py
List of dictionaries addDicts2List.py
Statistical calculations StatisticalCalculations.py
Classes and OOP ClassesAndMethods/Class1Employees.ipynb
Exception handling PrintInput.py
Jupyter Notebook ClassesAndMethods/Class1Employees.ipynb

Started on mobile. Finished with curiosity.

About

Here is a collection of my first python programs I developed using a mobile application to understant th theory behind python and the common key functions,methods, and keyowrds, to kickstart my python jpurney.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors