Loading...

My Learning Pad Login

Welcome

PCEP-30-02 Module 1: Comprehensive Teaching Material — Python Fundamentals


Table of Contents

  1. Module Overview & Syllabus
  2. Introduction to Computer Programming and Python
    • What is Python?
    • Python Program Structure
    • Comments
    • Indentation
    • Exercises
  3. Python Literals & Variables
    • Literals (int, float, string, bool)
    • Variable Naming Rules
    • Assignment
    • Multiple Assignments
    • Exercises
  4. Numeral Systems
    • Decimal, Binary, Octal, Hexadecimal
    • Converting Between Systems
    • Exercises
  5. Data Types & Operators
    • int, float, str, bool
    • Arithmetic Operators
    • Assignment Operators
    • Comparison Operators
    • Logical Operators
    • Type Casting
    • Exercises
  6. Console Input and Output
    • print() Function
    • input() Function
    • sep and end Parameters
    • Using int() and float() for Conversion
    • Exercises
  7. Practice Problems
  8. Summary Table

1. Module Overview & Syllabus


2. Introduction to Computer Programming and Python

What is Python?

Python Program Structure

# This is a simple Python program
print("Hello, world!")

Comments

Indentation

def greet():
    print("Hello!")  # Indented inside function

Exercises

  1. Write a Python program that greets a user by name.
  2. Write a comment describing what your program does.

3. Python Literals & Variables

Literals

Variables

user_name = "Alice"
PI = 3.14159
_is_visible = True

Assignment

a = 10
b = a + 5

Multiple Assignments

x, y, z = 1, 2, 3
x = y = z = 0  # Chain assignment

Exercises

  1. Assign your age, name, and student status to variables.
  2. Swap values using a temporary variable.

4. Numeral Systems

Decimal, Binary, Octal, Hexadecimal

num_dec = 255      # Decimal
num_bin = 0b11111111  # Binary
num_oct = 0o377    # Octal
num_hex = 0xFF     # Hexadecimal

Converting Between Systems

x = 42
print(bin(x), oct(x), hex(x))  # Output: binary, octal, hexadecimal

Exercises

  1. Convert decimal 100 to binary and hexadecimal.
  2. Determine the decimal value for 0b1010 and 0xF.

5. Data Types & Operators

Data Types

a = 10               # int
b = 5.5              # float
c = "Python"         # str
d = True             # bool
print(type(b))

Arithmetic Operators

+, -, *, /, //, %, **

Assignment Operators

=, +=, -=, *=, /=, //=, %=

Comparison Operators

==, !=, <, >, <=, >=

Logical Operators

and, or, not

Type Casting

val = int("5")       # str -> int
num = float(7)       # int -> float
text = str(True)     # bool -> str

Exercises

  1. Perform arithmetic and comparison on two numbers, show results.
  2. Cast a string number to integer and multiply by 2.

6. Console Input and Output

print("Welcome to Python")
print(1, 2, 3, sep="-")      # Output: 1-2-3
print("End", end="!
")        # Custom ending

input() Function

name = input("Enter your name: ")
age = int(input("Enter age: "))

Using int() and float() for Conversion

value = int(input("Enter an integer: "))
price = float(input("Enter price: "))

Exercises

  1. Program asks user for their name and prints a greeting.
  2. Ask user for two numbers and print their sum.

7. Practice Problems

  1. Write a program to check the type of variables after assignment.
  2. Ask user for three numbers and print their average.
  3. Write a code snippet that shows usage of all arithmetic operators.
  4. Input a number and print its binary, octal, and hex equivalents.
  5. Write a program to test if input is greater than 10 and print True/False.

8. Summary Table

Concept Syntax Example Notes
Literal 5, "abc", 3.14, True Fixed value
Variable x = 10 Named reference
Assignment a = b + 2 Store a value
Numeral systems 0b10, 0o10, 0x10 Binary, octal, hexadecimal
Data type type(x) int, float, str, bool
Operators +, -, *, /, ==, and Arithmetic, comparison, logical
print() print("hi", end="!") Printing output
input() x = input() Getting user input
Type casting int("5"), float("2.7") Convert between types

Use this module to learn all the foundational Python programming concepts needed for the PCEP-30-02 exam. Complete the examples and exercises for robust skills!