Welcome to UTSHPE's Coding Resource Center! 😎

Want to get started on your coding journey? Experience different programming languages? Or develop your own personal website? You're in the right place!

Explore, learn, and build with the resources we’ve prepared for you.

Getting Started with Python Syntax

Python is a high-level, interpreted programming language known for its readability and simplicity. It is widely used for web development, data analysis, artificial intelligence, scientific computing, and more. Here, you'll learn the basics of Python syntax, which will help you write clean and efficient code.

1. Basic Syntax

Python uses indentation to define code blocks, making the code more readable. Each block of code is indented consistently. For example, functions, loops, and conditionals are all defined with indentation.

2. Variables and Data Types

Variables in Python are dynamically typed, which means you don't need to declare their type explicitly. Common data types include integers, floats, strings, and lists. Here's how you can define variables:


# Defining variables
integer_var = 10
float_var = 10.5
string_var = "Hello, Python!"
list_var = [1, 2, 3, 4, 5]

print(integer_var, float_var, string_var, list_var)

3. Control Structures

Python supports various control structures, such as if statements, loops, and exception handling. Here's an example of a simple if statement and a for loop:


# If statement
number = 10
if number > 5:
    print("Number is greater than 5")

# For loop
for i in range(5):
    print("Loop iteration:", i)

Python Syntax Example

Below is a basic Python code snippet that demonstrates a simple print statement. This is one of the first things you'll learn in Python:

print("Hello, Python!")

Common Errors and Debugging

When starting with Python, you may encounter common syntax errors. Here are a few tips for debugging:

  • Indentation Errors: Ensure that your code blocks are consistently indented.
  • Syntax Errors: Check for missing colons or incorrect use of keywords.
  • Name Errors: Ensure that variables are defined before use.

Using a Python IDE or editor with built-in syntax checking can help catch these errors early.

Python Functions

Functions in Python allow you to write reusable blocks of code that perform a specific task. Functions can take inputs, process them, and return results. Here's a basic function:

def add(a, b):
    return a + b

result = add(5, 3)
print("Sum:", result)

1. Function Parameters and Return Values

Functions can take parameters, and they can return a value. Here's an example of a function with parameters and a return value:


def multiply(x, y):
    return x * y

result = multiply(4, 7)
print("Product:", result)

2. Default Parameters

Functions in Python can have default values for parameters, which will be used if no arguments are passed:


def greet(name="User"):
    print("Hello,", name)

greet()  # Will use the default value 'User'
greet("Alice")  # Will use 'Alice' as the name

Object-Oriented Programming (OOP) in Python

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects, which are instances of classes. Python allows you to define classes and create objects to model real-world entities.

1. Defining a Class

A class in Python is defined using the class keyword. Here's an example:


class Dog:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def bark(self):
        print(f"{self.name} is barking")

# Create an object (instance) of the Dog class
my_dog = Dog("Buddy", 3)
my_dog.bark()  # Output: Buddy is barking

2. Inheritance

Inheritance allows one class to inherit the properties and methods of another class. Here's an example:


class Animal:
    def __init__(self, name):
        self.name = name

    def speak(self):
        print(f"{self.name} makes a sound")

class Dog(Animal):
    def speak(self):
        print(f"{self.name} barks")

dog = Dog("Rex")
dog.speak()  # Output: Rex barks

Working with Python Modules

Modules in Python allow you to organize your code by breaking it into separate files. You can import a module in another file and use its functions or classes.

1. Importing Modules

Python comes with many built-in modules, such as math and datetime. You can also create your own modules. Here's an example:


# Importing a built-in module
import math

print(math.sqrt(16))  # Output: 4.0

# Importing a custom module
# Assume you have a file named 'my_module.py' with a function 'greet'
from my_module import greet

greet("Alice")  # Output: Hello, Alice

2. Creating Your Own Module

To create your own module, simply write a Python file with functions or classes, and then import it into other files. Here's an example of a module:


# my_module.py
def greet(name):
    print(f"Hello, {name}")

# main.py
from my_module import greet

greet("Alice")

Advanced Python Concepts

Now that you've learned the basics of Python, it's time to explore more advanced topics. These concepts will help you write more efficient and powerful code.

1. List Comprehensions

List comprehensions provide a concise way to create lists. Here's an example:


# Traditional way
squares = []
for i in range(10):
    squares.append(i**2)

# Using list comprehension
squares = [i**2 for i in range(10)]

2. Lambda Functions

Lambda functions are anonymous, inline functions that can take any number of arguments but have only one expression. Here's an example:


# Lambda function
square = lambda x: x ** 2

print(square(5))  # Output: 25

3. Generators

Generators allow you to iterate over large datasets without storing the entire dataset in memory. They yield one item at a time:


def count_up_to(max):
    count = 1
    while count <= max:
        yield count
        count += 1

counter = count_up_to(5)
for num in counter:
    print(num)

HTML Tags

HTML tags are used to structure content on a webpage. Below are some commonly used HTML tags with examples:

Paragraph Tag

The <p> tag defines a paragraph:

<p>This is a paragraph.</p>

Heading Tags

HTML provides six levels of headings, from <h1> (the largest) to <h6> (the smallest):


        <h1>Heading 1</h1>
        <h2>Heading 2</h2>
        <h3>Heading 3</h3>
        <h4>Heading 4</h4>
        <h5>Heading 5</h5>
        <h6>Heading 6</h6>

Link Tag

The <a> tag is used to create hyperlinks. Here's an example of linking to another page:

<a href="https://example.com">Visit Example</a>

Image Tag

The <img> tag is used to display images on a webpage. You must specify the image source and can include alternate text for accessibility:

<img src="image.jpg" alt="Description of the image" />

List Tags

HTML offers two types of lists: ordered (<ol>) and unordered (<ul>):


        <ul>
            <li>Item 1</li>
            <li>Item 2</li>
        </ul>
        
        <ol>
            <li>First Item</li>
            <li>Second Item</li>
        </ol>

Table Tag

The <table> tag is used to create tables. Here’s a simple example:

<table>
            <tr>
                <th>Name</th>
                <th>Age</th>
            </tr>
            <tr>
                <td>John</td>
                <td>30</td>
            </tr>
            <tr>
                <td>Jane</td>
                <td>25</td>
            </tr>
        </table>

HTML Syntax

HTML (HyperText Markup Language) is the standard language for creating web pages. Every HTML document follows a specific structure, which is essential for the correct rendering of web content. Here's a basic structure of an HTML document:

<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>HTML Syntax</title>
        </head>
        <body>
            <h1>Hello, World!</h1>
            <p>This is a basic HTML structure.</p>
        </body>
        </html>

Explanation:

  • <!DOCTYPE html>: This declaration tells the browser that the document is using HTML5, which is the latest version of HTML.
  • <html lang="en">: The html tag wraps the entire content of the webpage, and the lang="en" attribute specifies the language of the document (English, in this case).
  • <head>: The head section contains metadata about the webpage, such as the title, character encoding, and viewport settings for responsive design. This content is not displayed on the page itself.
  • <meta charset="UTF-8">: This meta tag defines the character encoding as UTF-8, which supports a wide range of characters and symbols.
  • <meta name="viewport" content="width=device-width, initial-scale=1.0">: This tag ensures that the webpage is displayed correctly on different devices, making the page responsive.
  • <title>: The text inside the title tag is what appears on the browser tab for the webpage.
  • <body>: The body tag contains all the visible content of the webpage, such as text, images, and other media elements.

Additional Examples of HTML Syntax

Here are a few more commonly used HTML elements that can be added to the body of a webpage:

Adding a List

You can create ordered and unordered lists using the <ol> and <ul> tags:

<h2>Ordered List Example</h2>
        <ol>
            <li>First item</li>
            <li>Second item</li>
            <li>Third item</li>
        </ol>
        
        <h2>Unordered List Example</h2>
        <ul>
            <li>First item</li>
            <li>Second item</li>
            <li>Third item</li>
        </ul>

In this example:

  • The <ol> tag creates an ordered (numbered) list, while the <ul> tag creates an unordered (bulleted) list.
  • The <li> tag represents each list item.
Adding Images

You can also add images using the <img> tag:

<img src="image.jpg" alt="A descriptive text" width="300" height="200">

Explanation:

  • src: The source attribute specifies the URL or path to the image file.
  • alt: The alternative text for the image, which is displayed if the image fails to load and helps with accessibility.
  • width and height: Define the dimensions of the image in pixels.
Adding Links

Links are created using the <a> tag. Here's how to add a hyperlink:

<a href="https://www.example.com" target="_blank">Visit Example</a>

Explanation:

  • href: The URL or web address the link points to.
  • target="_blank": Opens the link in a new tab.

Using CSS in HTML

CSS (Cascading Style Sheets) is used to style HTML elements and control the layout of web pages. It allows you to separate content (HTML) from presentation (CSS). Here's a simple example of how to set the background color of a webpage:

body {
            background-color: #f4f4f4;
        }

In this example, the background-color property changes the background color of the entire webpage to light gray.

Adding Color to Text

In addition to changing background colors, you can also style text by changing its color. Here's an example:

p {
            color: blue;
        }

This code will make all paragraphs <p> appear in blue. You can also use HEX values or RGB to define custom colors:

  • HEX value: #3498db for a specific shade of blue.
  • RGB: rgb(52, 152, 219) to define the same color using red, green, and blue values.

Styling Fonts

CSS allows you to control how text appears on the page. You can change the font family, size, and more. Here's an example:

p {
            font-family: Arial, sans-serif;
            font-size: 16px;
            font-weight: bold;
        }

Explanation:

  • font-family: Defines the font type. In this case, Arial will be used, and if it's not available, it will default to any sans-serif font.
  • font-size: Sets the size of the font to 16px.
  • font-weight: Makes the font bold.

Box Model in CSS

The CSS box model controls the spacing, padding, and borders of HTML elements. Here's an example:

div {
            width: 300px;
            padding: 10px;
            border: 2px solid black;
            margin: 20px;
        }

Explanation:

  • width: Sets the width of the <div> to 300px.
  • padding: Adds 10px of space inside the border.
  • border: Adds a solid black border with a thickness of 2px.
  • margin: Adds 20px of space outside the border to separate the element from others.

Using JavaScript in HTML

JavaScript is a programming language used to make web pages interactive. It allows you to respond to user actions, update content dynamically, and handle browser events. Here's a simple example that changes the content of a paragraph when the page loads:

document.getElementById("demo").innerHTML = "Hello, JavaScript!";

Explanation: This JavaScript code finds an HTML element with the id demo and changes its content to "Hello, JavaScript!".

HTML for this code:

<p id="demo">Original Text</p>

Event Handling in JavaScript

JavaScript allows you to handle events such as clicks, key presses, or page loads. Here's an example where a button click changes the content of a paragraph:

function changeText() {
            document.getElementById("demo").innerHTML = "You clicked the button!";
        }

The HTML for the button and paragraph would look like this:

<p id="demo">Original Text</p>
        <button onclick="changeText()">Click Me</button>

Explanation:

  • onclick: This event attribute in the button tag calls the JavaScript function changeText() when the button is clicked.
  • changeText(): This function changes the content of the paragraph with id demo.

Manipulating CSS with JavaScript

JavaScript can also be used to change CSS styles dynamically. Here's an example where clicking a button changes the background color of a <div>:

function changeBackgroundColor() {
            document.getElementById("colorBox").style.backgroundColor = "lightblue";
        }

The HTML for this would look like this:

<div id="colorBox" style="width: 100px; height: 100px; background-color: lightgray;"></div>
        <button onclick="changeBackgroundColor()">Change Color</button>

Explanation:

  • style.backgroundColor: This JavaScript property allows you to modify the CSS background color of an element.
  • onclick: Clicking the button triggers the changeBackgroundColor() function, which updates the background color of the <div>.

Getting Started

Welcome! To get started, download the following SHPE WebDev file and open it on the IDE of your choice. Once done, let's begin by understanding the key parts of your index.html file. You'll be editing the following areas:

1. Head Section

This is where you include metadata, links to stylesheets, and set the title of your website.

<head>
    <!-- Meta Data -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Poppins:100,200,300" rel="stylesheet">

    <!-- Title -->
    <title>Your Website Name</title>

    <!-- CSS Files -->
    <link rel="stylesheet" href="assets/css/style.css">
</head>

What to Edit:

  • Change the title to your name or site name:
  • <title>John Doe Portfolio</title>
  • Add or modify font links to customize typography.

Understanding the Structure

The structure of your website is defined by various HTML sections. Let's look at key sections you'll likely edit:

1. Navigation Bar

This is your site's main menu.

<nav class="navbar navbar-default bootsnav navbar-fixed dark no-background">
    <div class="container">
        <!-- Navbar Header -->
        <div class="navbar-header">
            <!-- Mobile Menu Button -->
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-menu">
                <i class="fa fa-bars"></i>
            </button>
            <!-- Logo -->
            <a class="navbar-brand" href="index.html">Your Name</a>
        </div>

        <!-- Navbar Menu -->
        <div class="collapse navbar-collapse" id="navbar-menu">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#about">About</a></li>
                <li><a href="#education">Education</a></li>
                <li><a href="#experience">Experience</a></li>
                <li><a href="#projects">Projects</a></li>
                <li><a href="#contact">Contact</a></li>
            </ul>
        </div>
    </div>
</nav>

What to Edit:

  • Replace Your Name in the logo area with your actual name or logo image.
  • Modify navigation links if you add or remove sections.

2. Welcome Hero Section

This is the first section visitors see.

<section id="welcome-hero" class="welcome-hero">
    <div class="container">
        <div class="row">
            <div class="col-md-12 text-center">
                <div class="header-text">
                    <h2>hi <span>,</span> i am <br> Your Name <br></h2>
                    <p>Your Profession</p>
                    <a href="assets/downloadables/Your_Resume.pdf" download>download resume</a>
                </div>
            </div>
        </div>
    </div>
</section>

What to Edit:

  • Change Your Name to your actual name.
  • Update Your Profession to reflect what you do (e.g., "Web Developer").
  • Replace the resume link with your own resume file.

Editing and Inserting

Now let's personalize your content.

1. About Me Section

<section id="about" class="about">
    <div class="section-heading text-center">
        <h2>about me</h2>
    </div>
    <div class="container">
        <div class="about-content">
            <div class="row">
                <div class="col-sm-6">
                    <div class="single-about-txt">
                        <h3>Brief Introduction</h3>
                        <p>Detailed description about yourself.</p>
                        <!-- Contact Info -->
                        <div class="row">
                            <div class="col-sm-4">
                                <div class="single-about-add-info">
                                    <h3>phone</h3>
                                    <p>Your Phone Number</p>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="single-about-add-info">
                                    <h3>email</h3>
                                    <p>Your Email</p>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="single-about-add-info">
                                    <h3>LinkedIn</h3>
                                    <p><a href="Your LinkedIn URL">LinkedIn Profile</a></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-5">
                    <div class="single-about-img">
                        <img src="assets/images/about/your_photo.jpg" alt="profile_image">
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

What to Edit:

  • Update the <h3> and <p> tags with your own introduction and details.
  • Replace contact information with your own.
  • Change the src attribute of the <img> tag to your profile picture.

2. Education Section

Add your educational background here.

<section id="education" class="education">
    <div class="section-heading text-center">
        <h2>education</h2>
    </div>
    <div class="container">
        <div class="education-horizontal-timeline">
            <div class="row">
                <div class="col-sm-4">
                    <div class="single-horizontal-timeline">
                        <div class="experience-time">
                            <h2>2015 - 2019</h2>
                            <h3>Bachelor of Science <span>in</span> Computer Science</h3>
                        </div>
                        <div class="timeline-content">
                            <h4 class="title">University Name</h4>
                            <h5>City, Country</h5>
                            <p class="description">Brief description of your studies.</p>
                        </div>
                    </div>
                </div>
                <!-- Add more entries as needed -->
            </div>
        </div>
    </div>
</section>

What to Edit:

  • Update the dates, degree, and field of study.
  • Replace the university name, location, and description.

3. Experience Section

Showcase your professional experience.

<section id="experience" class="experience">
    <div class="section-heading text-center">
        <h2>experience</h2>
    </div>
    <div class="container">
        <div class="experience-content">
            <div class="main-timeline">
                <ul>
                    <li>
                        <div class="single-timeline-box">
                            <div class="row">
                                <div class="col-md-5">
                                    <div class="experience-time text-right">
                                        <h2>2020 - Present</h2>
                                        <h3>Software Engineer</h3>
                                    </div>
                                </div>
                                <div class="col-md-5">
                                    <div class="timeline-content">
                                        <h4 class="title">Company Name</h4>
                                        <h5>City, Country</h5>
                                        <p class="description">Brief description of your role and achievements.</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </li>
                    <!-- Add more entries as needed -->
                </ul>
            </div>
        </div>
    </div>
</section>

What to Edit:

  • Update job titles, company names, dates, and descriptions.
  • Add or remove entries to match your experience.

4. Projects Section

Display your projects with images and descriptions.

<section id="projects" class="portfolio">
    <div class="section-heading text-center">
        <h2>Projects</h2>
    </div>
    <div class="container">
        <div class="portfolio-content">
            <div class="row">
                <div class="col-sm-4">
                    <div class="item">
                        <img src="assets/images/portfolio/project1.jpg" alt="Project 1">
                        <div class="isotope-overlay">
                            <a href="Project1_URL">
                                Project Title
                            </a>
                        </div>
                    </div>
                </div>
                <!-- Add more projects as needed -->
            </div>
        </div>
    </div>
</section>

What to Edit:

  • Replace image sources with your project images.
  • Update project titles and links.

JavaScript Effects

Enhance your site with interactive effects.

1. Smooth Scrolling

Add smooth scrolling to your navigation links.

<!-- Include jQuery -->
<script src="assets/js/jquery.js"></script>

<!-- Custom JS -->
<script>
    $(document).ready(function(){
        $('a[href^="#"]').on('click',function (e) {
            e.preventDefault();

            var target = this.hash;
            $('html, body').animate({
                scrollTop: $(target).offset().top
            }, 1000);
        });
    });
</script>

2. Custom Animations

Use CSS classes to add animations.

<!-- In your HTML -->
<div class="animated fadeIn">Your Content</div>

<!-- In your CSS -->
.animated {
    animation-duration: 1s;
    animation-fill-mode: both;
}
.fadeIn {
    animation-name: fadeIn;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

Note: You can adjust the animation effects by editing or adding classes.

Deployment

Now, let's deploy your website using GitHub Pages. This free service allows you to host your personal website directly from a GitHub repository.

Step-by-Step Guide:

  1. Initialize a Git Repository: In your project folder, open your terminal and run the following commands to initialize the repository and commit your files:
    git init
    git add .
    git commit -m "Initial commit"
  2. Create a GitHub Repository: Go to GitHub and create a new repository named username.github.io (replace "username" with your GitHub username).
  3. Push Your Code: Connect your local repository to GitHub and push your code by running the following commands:
    git remote add origin https://github.com/username/username.github.io.git
    git branch -M main
    git push -u origin main
  4. Access Your Site: After pushing your code, your website will be live at https://username.github.io.

For more detailed instructions on deploying with GitHub Pages, check out the official documentation at GitHub Pages Documentation.

Additional Tips:

  • Ensure all your asset paths (CSS, images, JS) are relative, so they work correctly when hosted on GitHub Pages.
  • If your website isn't displaying as expected, verify your repository's settings under "Settings" > "Pages".

Maintenance

Keep your website updated and running smoothly.

1. Content Updates

Regularly update your site with new projects, experiences, or skills.

2. Monitoring and Bug Fixes

Check your site periodically for any issues such as broken links or images.

3. Version Control

Use Git to manage changes. Commit and push updates to GitHub to keep your site current.

4. Enhancements

Add new features or redesign your site as your skills grow.