0% found this document useful (0 votes)
4 views3 pages

AOICT3

Uploaded by

Nabia Faisal
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)
4 views3 pages

AOICT3

Uploaded by

Nabia Faisal
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/ 3

AOICT-03

Introduction to Python and Google Colab

1. Google Colab Overview (Slides 40–44):


o What is Colab?
 A cloud-based environment for writing and running Python programs.
 Accessible with zero configuration and GPU support.
o Key Features:
 Cells: Can contain code or explanatory text.
 Execution Commands:
 Ctrl+Enter: Runs a cell in place.
 Shift+Enter: Runs the cell and moves to the next.
 Alt+Enter: Runs the cell and adds a new cell below.

Python Basics

2. Printing in Python (Slides 45–48):


o Basic Printing:
 print("Hello, World!") outputs text.
Arithmetic in Print:
o
 Expressions like print(5 + 10) evaluate before printing.
o Multiple Inputs:
 print("My name is", "Alice", "and I am", 25) separates inputs
with spaces.
o Practice Activities:
 Tasks like printing names, favorite colors, or mathematical results.
3. Comments (Slides 50):
o Single-Line Comments: Use # to annotate code.
o Multi-Line Comments: Use triple quotes (""" comment """) to block
comments.

Python Operators

4. Arithmetic Operators (Slides 51–52):


o Perform basic math: +, -, *, /, %, ** (exponentiation), and // (floor division).
5. Assignment Operators (Slide 52):
o Assign values with = and modify with +=, -=, etc.
6. Comparison Operators (Slide 53):
o Used to compare values: ==, !=, >, <, >=, <=.
Working with Variables

7. Variable Basics (Slides 54–56):


o Variables store data for reuse:
o name = "Alice"
o age = 25
o print("Name:", name, "Age:", age)
o Multiple Assignments:
o x, y, z = 10, 20, 30
o a = b = c = 5
8. Variable Types (Slides 58–60):
o Common Types:
 Strings ("Hello"), Integers (10), Floats (3.14), Booleans (True/False).
o Check Types: Use type(variable) to identify types.
9. Typecasting (Slides 61–62):
o Convert data types using:
 int(), float(), str():
 age_str = "25"
 age = int(age_str) # Converts string to integer

User Input (Slides 63–64):

 Taking Input:
o Use input() to get user responses:
o name = input("Enter your name: ")
o print("Hello", name)
 Convert Input:
o Input is always a string; cast to other types as needed:
o number = int(input("Enter a number: "))

Strings in Python

10. String Manipulations (Slides 65–68):


o Concatenation: Combine strings with +.
o greeting = "Hello, " + "World!"
o Replication: Repeat strings with *.
o print("Hi " * 3) # Output: Hi Hi Hi
o Slicing: Extract parts of a string using indices.
o text = "Python"
o print(text[0:3]) # Output: Pyt
o Length: Find string length with len().
o print(len("Hello")) # Output: 5

Advanced Variable Usage


11. Manipulating Variables (Slides 57, 74–75):
o Overwriting values updates the variable:
o x = 10
o x = x + 5 # x becomes 15
12. Swapping Variables (Slides 76–78):
o Using a temporary variable:
o a, b = 5, 10
o temp = a
o a = b
o b = temp
o Without a temporary variable:
o a, b = 5, 10
o a = a + b
o b = a - b
o a = a - b
o Using tuple unpacking:
o a, b = b, a

Practice Problems (Slides 70–73):

1. Calculate the circumference and area of a circle:


2. pi = 3.14
3. radius = 5
4. circumference = 2 * pi * radius
5. area = pi * radius**2
6. print("Circumference:", round(circumference, 2))
7. print("Area:", round(area, 2))
8. Predict results of variable manipulations and swapping tasks.

Key Takeaways

 Master Python basics such as printing, variables, and string manipulation.


 Understand operators and data type conversions for effective coding.
 Utilize Google Colab for coding practice and collaboration.
 Strengthen concepts with hands-on activities like swapping variables and calculating
circle properties.

You might also like