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

Day 1 - Introduction to Python Programming

The document provides an introduction to programming, specifically using Python, explaining its importance, applications, and basic concepts such as syntax, variables, and data types. It includes practical steps for setting up Python and Visual Studio Code, along with quizzes and exercises to reinforce learning. The document emphasizes the role of programming in automating tasks, solving problems, and creating software.

Uploaded by

Sivaram S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Day 1 - Introduction to Python Programming

The document provides an introduction to programming, specifically using Python, explaining its importance, applications, and basic concepts such as syntax, variables, and data types. It includes practical steps for setting up Python and Visual Studio Code, along with quizzes and exercises to reinforce learning. The document emphasizes the role of programming in automating tasks, solving problems, and creating software.

Uploaded by

Sivaram S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Introduction to Python

Programming
1.1 What is Programming?
Programming is the process of writing instructions that tell a computer
how to perform a task. These instructions are written in programming
languages such as Python, Java, or C++.
Real-Life Example:
Think of programming like telling a robot to clean your house. You would
give it step-by-step instructions like:
● Pick up the vacuum,
● Move to the kitchen,
● Vacuum the floor, and so on. The robot doesn’t know what to do until
you tell it (through code).
1.2 Why Do We Need Programming?
Programming is essential because it allows us to make computers do
useful things—from solving complex problems to automating simple
tasks.
Uses of Programming:
1. Automation: You can automate repetitive tasks, like sending emails
or organizing files.
2. Problem-Solving: Programming helps solve mathematical,
engineering, or data analysis problems.
3. Creating Websites: Programming is used to create web pages and
apps that we use every day.
4. Building Software: Programming is used to create everything from
video games to business applications.
1.3 Where and How is Programming Used?

● Everywhere: Programming is used in almost everything we interact


with in the modern world—smartphones, websites, social media
platforms, etc.
● Companies Using Programming:
a. Google uses Python to manage their search algorithms.
b. Netflix uses programming to recommend movies based on user
preferences.
c. NASA uses programming for space exploration and simulations.
● Examples of Real-World Applications:
a. Mobile apps (WhatsApp, Instagram) – Built using programming.
b. Self-driving cars – Powered by AI (programming).
QUIZ
1. Programming is the process of:
a) Giving instructions to humans
b) Giving instructions to computers
c) Designing computer hardware
d) Using applications on a computer
QUIZ
1. Programming is the process of:
a) Giving instructions to humans
b) Giving instructions to computers
c) Designing computer hardware
d) Using applications on a computer
Answer: b
QUIZ
2. Which of these is an example of a programming language?
a) Python
b) HTML
c) C++
d) All of the above
QUIZ
2. Which of these is an example of a programming language?
a) Python
b) HTML
c) C++
d) All of the above
Answer: d
QUIZ
3. Which device uses programming to function?
a) A smartphone
b) A washing machine
c) A traffic light system
d) All of the above
QUIZ
3. Which device uses programming to function?
a) A smartphone
b) A washing machine
c) A traffic light system
d) All of the above
Answer:d
Setting Up Python (Installation Instructions)
Step 1: Open Your Web Browser
● use Google Chrome, Firefox, Safari, or Opera.
Step 2: Search for Python

● In the browser's search bar, type "Python" and press Enter.


a. Important: Make sure you are visiting the official Python website, which should be
at the address python.org. If you're on another site, don't click on it.
Step 3: Download Python

1. After clicking the search result, you should see a Download button for Python..
○ This download page should show a button labeled "Download Python".
○ Click that button to start the download.
2. Once the download is complete, locate the downloaded file (typically in the Downloads
folder).
Step 4: Run the Python Installer

1. Double-click the installer file to start the installation process.


○ You’ll see a setup window pop up.
2. IMPORTANT: Make sure to check the box that says "Add Python to PATH". This will
allow you to run Python from anywhere on your computer.

3. Click "Install Now" to begin the installation process.

1
Step 5: Verify Python Installation

After the installation is complete, let's check if Python was installed correctly.

1. Open Command Prompt (Windows):


○ Click on the Start Menu and type "cmd" in the search bar, then press
Enter.
○ A black window should pop up. This is your Command Prompt.
2. Check Python Installation:
● Type the following command “python --version”
into the Command Prompt and press Enter:
● You should see something like: Python 3.x.x (the
version you just installed). This confirms that Python is
installed.
Download Visual Studio Code (VS Code)
Step 1: Open Your Web Browser
● use Google Chrome, Firefox, Safari, or Opera.
In the search bar, type "VS Code" and go to the official
website.

2
Installing VS Code:

● After the file has downloaded, open the


installer and follow the instructions.

2
3

4
Using VS Code for Python
● Install the Python extension by clicking on the Extensions icon (four
squares) on the left sidebar.
1. create a new file by selecting File > New File.
2. Select Python File
3. Write the code print(‘Hello, World!’)
4. save the file with any name ex: first program.py (Important: py is python
extension)

5. To run the program, you can use shortcut f5 or go to run > start debugging
or with play button in the right side of the screen
6
1
3

2
4
5
● If used f5 or run > start debugging, Select Python
Debugger > Python File

(Output)
Answer: c
1.6 Understanding Python Syntax
What is Syntax?

Syntax is the set of rules that tell Python how to understand your instructions. If you make a
mistake in your syntax, Python will show an error.

Explanation:

● print() is a function that outputs text to the screen.


● "Hello, World!" is a string of text.
Quiz
1. What does the print() function do in Python?
a) It takes input from the user.
b) It displays output on the screen.
c) It comments the code.
d) It defines a variable.
Quiz
1. What does the print() function do in Python?
a) It takes input from the user.
b) It displays output on the screen.
c) It comments the code.
d) It defines a variable.
Answer: b
Quiz
2. Which of the following is the correct way to print a
message in Python?
a) print["Hello, World!"]
b) print("Hello, World!")
c) print{"Hello, World!"}
d) print<"Hello, World!">
Quiz
2. Which of the following is the correct way to print a
message in Python?
a) print["Hello, World!"]
b) print("Hello, World!")
c) print{"Hello, World!"}
d) print<"Hello, World!">
Answer: b
Quiz
3. What is the output of the following code?
print("Python is fun!")
a) Python is fun!
b) "Python is fun!"
c) python is fun!
d) Error
Quiz
3. What is the output of the following code?
print("Python is fun!")
a) Python is fun!
b) "Python is fun!"
c) python is fun!
d) Error
Answer: a
EXERCISE
1. Create and save a python file with any name
2. Write a program to print your name and run the program
Single Line Comments
Comments are lines that Python ignores. They are for you to leave notes
in your code. The comment or commented line will not printed in the
output. Single line comment is denoted by “#(Hashtag)”
Multiline Comment are denoted by “Triple quotes”
Ex: ‘’’(Triple Single Quotes) or “””(Triple Double Quotes)
Quiz
How do you write a single-line comment in Python?
a) Using //
b) Using #
c) Using /* */
d) Using <!-- -->
Quiz
How do you write a single-line comment in Python?
a) Using //
b) Using #
c) Using /* */
d) Using <!-- -->
Answer: b
Quiz
Which of the following is a valid comment in Python?
a) # This is a comment
b) // This is a comment
c) <!-- This is a comment -->
d) /* This is a comment */
Quiz
Which of the following is a valid comment in Python?
a) # This is a comment
b) // This is a comment
c) <!-- This is a comment -->
d) /* This is a comment */
Answer: a
Exercise
1. Write a single line and multi line comment
Variables and Data Types
What is a Variable?

A variable is like a box that holds information. You can store data in a variable
and give it a name so you can refer to it later.

Ex: A delivery box containing item


Variable Names
● A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).
Rules for Python variables:
● A variable name must start with a letter or the underscore character
● A variable name cannot start with a number
● A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
● Variable names are case-sensitive
○ Ex: (age, Age and AGE are three different variables. So should be careful with capitals and small
letters)
MCQ
What is a valid variable name in Python?

A) 1st_variable

B) first_variable

C) first-variable

D) first variable
MCQ
What is a valid variable name in Python?

A) 1st_variable

B) first_variable

C) first-variable

D) first variable

B) first_variable
MCQ
What is a variable in Python?
a) A function to print data
b) A way to store data in memory
c) A method to execute Python scripts
d) A type of Python file
MCQ
What is a variable in Python?
a) A function to print data
b) A way to store data in memory
c) A method to execute Python scripts
d) A type of Python file
Answer: b
MCQ
Which of the following is a correct variable assignment?
a) x = 5
b) 5 = x
c) x =
d) x == 5
MCQ
Which of the following is a correct variable assignment?
a) x = 5
b) 5 = x
c) x =
d) x == 5
Answer: a
Exercise
Create three variables: x, y, and z, and assign the values 10,
5.5, and "Hello" to them respectively. Print the values of all
three variables on separate lines.
Exercise Solution
x = 10
y = 5.5
z = "Hello"
print(x)
print(y)
print(z)
Assigning values to variables
● Left side is variable name
● Right side is value and value can be any anything
○ Ex: string(letters, words, sentence),
integer(number) etc.
Multi Words Variable Names
Variable names with more than one word can be difficult to read.

There are several techniques you can use to make them more readable:

Camel Case

Each word, except the first, starts with a capital letter:

Pascal Case

Each word starts with a capital letter:

Snake Case

Each word is separated by an underscore character:


MCQ
Which of the following is an example of PascalCase?
a) my_variable_name
b) MyVariableName
c) myVariableName
d) my-variable-name
MCQ
Which of the following is an example of PascalCase?
a) my_variable_name
b) MyVariableName
c) myVariableName
d) my-variable-name
Answer: b
Exercise

1. Create a variable using with name my favorite color using


snake case technique and assign it any color string and
print it
Exercise Solution
my_favorite_color = "Blue"
print(my_favorite_color)
What are Data Types?
Data types define the kind of data stored in variables. Common data types
include:

● String: Used for text.


○ Example: "Alice"
● Integer: Used for whole numbers.
○ Example: 25
● Float: Used for decimal numbers.
○ Example: 3.14
● Boolean: Can only be True or False.
○ Example: True
A String is a stream of characters enclosed within
quotes.
Ex:(letters, words, sentence, numbers) in single or
double quotations
Important: Boolean is also
case-sensitive the first letter in both
True and False are capital
MCQ
What is the data type of the value 42?
a) String
b) Integer
c) Float
d) Boolean
MCQ
What is the data type of the value 42?
a) String
b) Integer
c) Float
d) Boolean
Answer: b
MCQ
What is the data type of "Hello, World!"?
a) String
b) Integer
c) Float
d) Boolean
MCQ
What is the data type of "Hello, World!"?
a) String
b) Integer
c) Float
d) Boolean
Answer: a
MCQ
Which data type is used to store decimal numbers?
a) Integer
b) Float
c) String
d) Boolean
MCQ
Which data type is used to store decimal numbers?
a) Integer
b) Float
c) String
d) Boolean
Answer: b
Exercise
Define the following variables and print their data types
1. Name,
2. Age,
3. Height,
4. is_student
Exercise Solution
name = "Alice"
age = 25
height = 5.6
is_student = True
print(type(name))
print(type(age))
print(type(height))
print(type(is_student))

You might also like