0% found this document useful (0 votes)
7 views

CB VI Computer Studies Introduction To Python

Uploaded by

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

CB VI Computer Studies Introduction To Python

Uploaded by

sindhu pramod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Subject: Computer Studies

Topic: Introduction to Python

Grade: VI

CB/VI/2021 Introduction to Python 1 of 28


Learning Objective

• create and execute a program in Python


• define and assign values to variables
• use variables in a program
• use built-in functions of Python
• use arithmetic operators for performing
calculations

CB/VI/2021 Introduction to Python 2 of 28


Introduction to Python
• Python is a highly popular, powerful and
widely used high-level programming
language.

• Python can be used to build websites,


Enterprise Resource Planning (ERP) and e-
commerce systems, perform data analysis
and, perform scientific and numeric
computations.

CB/VI/2021 Introduction to Python 3 of 28


Features to Python
• It is easy to learn.

• It is free. You can use it for free and also


make changes to its source code and
distribute copies of the same (open source).

• It is an interpreted language. You can run a


program directly from the source code
without compiling it.

CB/VI/2021 Introduction to Python 4 of 28


Using IDLE
IDLE, Python’s Integrated Development and Learning
Environment for creating and executing programs.

It can be used in two ways—


• by using the interactive interpreter prompt
or
• by using a source file.

When you first start IDLE, the Python shell is displayed


where you can type and execute instructions
interactively.

CB/VI/2021 Introduction to Python 5 of 28


Using IDLE
When you first start IDLE, the Python shell is displayed
where you can type and execute instructions
interactively.

CB/VI/2021 Introduction to Python 6 of 28


Error message
Python commands will not execute if there is an error in
its syntax; instead, it will display an error message with a
description of the error as shown in the screen.

CB/VI/2021 Introduction to Python 7 of 28


Typing, Saving and Executing a Python Program

We cannot type a program having multiple instructions


at the prompt every time we want to run it; therefore,
we need an editor using which we can save our source
programs and run them any number of times.

IDLE, PyCharm, Vim and Emacs are examples of some


special editors, also called Integrated Development
Environment (IDE), that you can use for typing, saving
and executing Python programs.

CB/VI/2021 Introduction to Python 8 of 28


Typing, Saving and Executing a Python Program
You can type a new program in IDLE by selecting the
New File option from the File menu. Type the program
and save the file with an extension “.py”.

You can test the program for errors by selecting the


Check Module option and run it by selecting the Run
Module option.

CB/VI/2021 Introduction to Python 9 of 28


Typing commands in Python

Type print(9+1) at the prompt and press the Enter key.


It will execute the print command to give the output
10.

CB/VI/2021 Introduction to Python 10 of 28


The print() command

• The Print() command is used to display the


output on the screen. It can be used to display a
string or the result of a calculation.

• The string refers to a sequence of letters or


other characters. It is generally enclosed in
single or double quotes.

CB/VI/2021 Introduction to Python 11 of 28


The print() command examples

• print(“This is my first program”) will simply


display the message inside the quotes as it is.

• print(36+4)will calculate the sum of 36 and 4


and display the result as 40.

• print(100/4) will divide 100 by 4 and display 25.

CB/VI/2021 Introduction to Python 12 of 28


The print() command examples

• print(35*2) will multiply 35 by 2 and display the


product 70.

• print(“\n”) uses a special character “\n” used to


start a new line.

• print(‘This is another way!’)will display the


message- This is another way!.

CB/VI/2021 Introduction to Python 13 of 28


Comments
• A Python command can include comments that
are meant to help someone else understand
your code. They are ignored by the Python
interpreter.
• Comments start with a ‘#’.

CB/VI/2021 Introduction to Python 14 of 28


Variables
• A variable is a named storage area in the
computer memory used to store a value.
• You can change the value of data stored in this
area but the name of the variable will remain
the same.
• Every variable must be named. The name given
should be meaningful so that you can remember
what the variable is used for in the program.
• For example, alphabet, numeric digit and
underscores (A-Z, 0-9 or _)

CB/VI/2021 Introduction to Python 15 of 28


Rules for creating Python variables

• A variable name can contain an alphabet,


numeric digit and underscores (A-Z, 0-9 or _).
• A variable name should start with either a letter
or an underscore. It cannot start with a numeric
digit.
• Variable names are case-sensitive. A variable in
lower case is different from the same variable in
uppercase. For example, age, Age and AGE are
three different variables.

CB/VI/2021 Introduction to Python 16 of 28


Data Types
• Different types of data are stored in different
ways in the computer memory. Every variable has
a data type in Python. Python decides the type of
data of a variable by looking at the value given to
it.
• To define a variable, you need to assign a value to
it using the equals sign. score=0 will store 0 in
score.
• answer=’A’ will store the character ‘A’ in answer.
• percentage = 98.56 will store 98.56 in
percentage.
CB/VI/2021 Introduction to Python 17 of 28
Assigning a value to a variable
A variable is like an empty box. You must put data
into the variable. This is called assigning a value
to a variable. Python allows assigning value to
single and multiple variables.

CB/VI/2021 Introduction to Python 18 of 28


Accepting values from a user

A program also needs to take some input from a


user. This can be done using the input()
command.

CB/VI/2021 Introduction to Python 19 of 28


Arithmetic Operators
Arithmetic operators allow you to carry out calculations in
Python. The main arithmetic operators available in Python
are +, -, *, /, %, ** and //.

CB/VI/2021 Introduction to Python 20 of 28


Python’s Built-in Functions
Int(): The int() function is used for performing arithmetic
operations on the input entered by the user in the previous
example.

CB/VI/2021 Introduction to Python 21 of 28


Python’s Built-in Functions
Float(): The float() function converts a specified value into a
floating point number.

CB/VI/2021 Introduction to Python 22 of 28


Python’s Built-in Functions
Format(): The format() function formats a value into a
specified format. For example, comma (,), Underscore (_),
Percentage (%)

CB/VI/2021 Introduction to Python 23 of 28


String functions

CB/VI/2021 Introduction to Python 24 of 28


String functions examples

CB/VI/2021 Introduction to Python 25 of 28


String functions examples

CB/VI/2021 Introduction to Python 26 of 28


Designing a Simple Calculator

CB/VI/2021 Introduction to Python 27 of 28


Designing a Simple Calculator

CB/VI/2021 Introduction to Python 28 of 28

You might also like