Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Introduction to Programming Class Notes

The document provides an introduction to Python programming, covering its syntax, control structures, and functions. It explains basic concepts such as data types, input/output functions, conditional statements, loops, and the use of modules. Practical exercises, including a number-guessing game and a calculator, are suggested to reinforce learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Introduction to Programming Class Notes

The document provides an introduction to Python programming, covering its syntax, control structures, and functions. It explains basic concepts such as data types, input/output functions, conditional statements, loops, and the use of modules. Practical exercises, including a number-guessing game and a calculator, are suggested to reinforce learning.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Introduction to Programming Class Notes

Page 1: Basics of Python Syntax


Python is a high-level, interpreted programming language known for its readability and versatility.
Unlike compiled languages, Python executes code line-by-line, making debugging easier for
beginners. Variables in Python are dynamically typed, meaning you don’t need to declare data types
explicitly. For example, name = "Alice" assigns a string, while age = 25 assigns an integer. Basic data
types include strings (text), integers (whole numbers), floats (decimals), and booleans (True/False).

Input and output functions like print() and input() allow interaction. A simple "Hello World" program
would be:

print("Hello, World!")

user_name = input("Enter your name: ")

print("Welcome,", user_name)

Common errors include syntax errors (e.g., missing colons or parentheses) and runtime errors (e.g.,
dividing by zero). Always check indentation, as Python uses whitespace to define code blocks.

Page 2: Control Structures

Control structures direct the flow of a program. Conditional statements like if, elif, and else
execute code based on Boolean conditions. For example:

temperature = 30

if temperature > 25:

print("It's a hot day.")

else:

print("Cool weather!")

Loops repeat actions: for loops iterate over sequences (e.g., lists), while while loops run until
a condition is false. Use break to exit a loop early or continue to skip iterations. Logical
operators (and, or, not) combine conditions.
A practical exercise is building a number-guessing game:

import random

target = random.randint(1, 10)

guess = 0

while guess != target:

guess = int(input("Guess a number (1-10): "))

print("Correct!")

Page 3: Functions and Modules

Functions encapsulate reusable code. Define them with def, followed by parameters:

def add_numbers(a, b):

return a + b

Parameters are variables in the function definition; arguments are the actual values passed.
Modules like math (for sqrt, sin) or random (for randint, choice) extend functionality. Import
them with import module_name.

Variable scope determines accessibility: variables inside a function are local, while those
declared outside are global. For example:

x = 10 # Global

def test():

y = 5 # Local

print(x + y)

test()

Practice by creating a calculator that uses functions for addition, subtraction, etc.

You might also like