0% found this document useful (0 votes)
5 views4 pages

Aku Cs Python Notes

The document provides comprehensive notes on Python programming, covering key concepts such as programming languages, syntax vs semantics, and types of programming languages. It includes sections on Turtle graphics, libraries, constants and variables, input/output, operators, selection statements, and loops with examples. The notes serve as a guide for students in HSSC Computer Science at AKUCS.

Uploaded by

rumaisa abid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Aku Cs Python Notes

The document provides comprehensive notes on Python programming, covering key concepts such as programming languages, syntax vs semantics, and types of programming languages. It includes sections on Turtle graphics, libraries, constants and variables, input/output, operators, selection statements, and loops with examples. The notes serve as a guide for students in HSSC Computer Science at AKUCS.

Uploaded by

rumaisa abid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Comprehensive Python Notes for AKUCS HSSC Computer Science

3.1 Introduction to Programming

3.1.1 Program and Programming Language - Program: A set of instructions written to perform a specific
task. - Programming Language: A formal language to write programs (e.g., Python, C, Java).

3.1.2 Syntax vs Semantics - Syntax: Rules to write correct code. Example: print("Hello") . -
Semantics: Meaning of the code. Example: print(5 + 2) prints 7.

3.1.3 Types of Programming Languages - Low-level: Machine Language (binary), Assembly Language
(mnemonics). - High-level: Procedural (step-by-step, e.g., Python), Structured (functions & loops, e.g., C),
Object-oriented (objects, e.g., Java).

3.1.4 Assembler, Compiler, Interpreter - Assembler: Assembly -> Machine code - Compiler: Entire
program -> Machine code - Interpreter: Line by line execution

3.1.5 Python Language & Applications - Python: High-level, interpreted, general-purpose. - Applications:
Web dev, data analysis, machine learning, bioinformatics.

3.1.6 Python IDE - Integrated environment to write, test, debug code. Examples: IDLE, PyCharm, VS
Code, Thonny.

3.1.7 Comments in Python - Single-line: # comment - Multi-line: """ comment """

3.2 Turtle Graphics

3.2.1 Define Turtle Graphics - Draw shapes and graphics using a virtual turtle.

3.2.2 Using Turtle Library

import turtle
t = [Link]()

3.2.3 Functions - Movement: forward() , backward() , right() , left() - Screen: bgcolor() ,


title() , clear() , reset() , stamp() - Attributes: pensize() , fillcolor() , color() ,
shape() , speed() - Shapes: circle() , dot()

Example:

for _ in range(4):
[Link](100)
[Link](90)

1
3.3 Libraries

3.3.1 Purpose: Pre-written code for faster development. 3.3.2 Installing:


pip install library_name 3.3.3 Example with datetime:

import datetime
now = [Link]()
print([Link]('%A'), [Link]('%B'), [Link]('%Y'))

3.4 Constants and Variables

3.4.1 Data Types: int, float, str, char, bool 3.4.2 Variable vs Constant: Variable changes, Constant fixed
(e.g., PI = 3.14 ) 3.4.3 Local vs Global: Local inside function, Global accessible anywhere 3.4.4
Naming Rules: Start with letter/_ , no spaces, no special chars 3.4.5 Example:

x = 10
y = 3.14
name = 'Alice'
is_human = True
z = int(y) # explicit
a = 5 + 3.2 # implicit

3.5 Input/Output

• input() takes user input


• print() displays output
• eval() converts string input to expression

x = eval(input('Enter number: '))


print('Value:', x)

3.6 Operators

• Assignment: =
• Arithmetic: + - * / % **
• Comparison: == != > < >= <=
• Logical: and or not
• Membership: in, not in
• Bitwise: & | ^ ~ << >>

Example:

2
a = 5
b = 3
print(a + b, a > b, a & b, a > 0 and b < 5)

3.7 Selection Statements

• if , if-else , if-elif-else , nested if , pass

x = 10
if x > 5:
print('x > 5')

if x < 5:
print('x < 5')
else:
print('x >= 5')

marks = 75
if marks >= 90:
print('Grade A')
elif marks >= 70:
print('Grade B')
else:
print('Grade C')

if age >= 18:


if has_id:
print('Entry allowed')

if age < 18:


pass

3.8 Loops

• For loop: fixed repetitions


• While loop: until condition false
• Nested loops: loop inside loop
• Break, Continue, Exit

for i in range(5):
if i == 3: break
print(i)

for i in range(5):
if i == 3: continue

3
print(i)

import sys
[Link]()

You might also like