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

Programming in Phyton - Sequence

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

Programming in Phyton - Sequence

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

Programming in

PHYTON:
Sequence
Introduction
• Any task that we perform include a various step.
• Computer follows stepwise instructions to complete any task which is known as
Program.
• E.g., game or application
• A program consist of set of instructions.
• Three basics programming construct: Sequence, Selection, Iteration.
• The language used to write programs is called Programming Language.
• There are many different programming language use to write computer programs.
• E.g., Java, Ruby, JavaScript, SQL, Python and many more!
• The person who writes the programs is known as programmer.
Programming
Constructs
• Sequence is the order in which
instructions occur and are
processed.
• Selection determines which path
a program takes when it is
running.
• Iteration is the repeated
execution of a section of code
when a program is running
Python is a computer programming language often
used to build websites and software, automate
tasks, and conduct data analysis. Python is a
general-purpose language, meaning it can be used to
create a variety of different programs and isn't
specialized for any specific problems.
Why
?
• It’s Free!
• Easy to learn
• Exceptionally powerful
• Universally accepted,
• Effective
• Superb Learning and Educational too.
What can you do with
?
• Web Development
• Software Development
• Gaming
• Artificial Intelligence
Using IDLE

• IDLE (short for Integrated


Development Environment) is a free
app that you get when you install
Python. Designed for beginners, IDLE
includes a basic text editor that
allows you to write and edit Python
code.
• IDLE has two different windows in
which you can work. The editor
window can be used to write and
save programs, while the shell
window runs Python instructions
immediately.
The shell window

• When you open IDLE, the shell window


pops up.
• This is the best place to get started in
Python because you don’t have to
create a new file first.
• Just type the code directly into the
shell window. The >>> is called a prompt, and it
means that the computer is ready to
accept your first command
The editor window
• The shell can’t save your code, so when you
close the shell window the code you typed is
lost forever.
• That’s why you should use IDLE’s editor
window when you work on a project.
• This window lets you save your code.
• It also has built-in tools to help you write your
programs and to trouble-shoot any errors.
• To open the editor window in IDLE, click on the
File menu at the top and choose New File.
• An empty editor window will then appear.
• You’ll use the editor window to write and run
programs
.py files

• Python programs usually have a


name ending with “.py”, which
makes them easy to recognize.
When you save a program,
Python automatically adds “.py”
at the end, so you don’t need to
type it in.
CHAPTER: PROGRAMMING IN PHYTON
Variables

• A variable is containers for storing data values.


• A variable is created the moment you first assign a value to it.

x=5
You can put any name to variable. BUT MUST FOLLOW THESE RULES:

• Must start with letter. CANNOT start with a number.


• Can only contain letters, numbers and the underscore symbol
• Case sensitive.
WRONG WAY NAMING
2myvar = "John"
VARIABLE !!!!!!
my-var = "John"
my var = "John"
CHAPTER: PROGRAMMING IN PHYTON
Getting data from users
Code Output:
name = input ( ‘ Enter your first name: ’
)
print (name)
What this code do?
- First it will ask user to enter first name.
- When the user enter their first name, it will be store
in a name variable.
- Next it will printout the first name by calling the
variable name.

• name  is a variable name. Data is store in a name


• input  is a command to ask user to enter data. Data enter is in a string data type.
• print  is a command to display the output
CHAPTER: PROGRAMMING IN PHYTON
Concatenation You can think
string is like a
sentence
The + operator lets you combine two or more strings in Python.
Code
name = input ( ‘ Enter your first name: ’ )
print (“Hi Welcome to our class, ” + name)

Output:
CHAPTER: PROGRAMMING IN PHYTON
Data Types
Data types is a classification of data. There are 3 common data types: Strings, Integers, and
Floating-Point Numbers (Real numbers).
e.g. pi = 3.15 Floating point number

radius = 6 Integer

name = “John” String

Data entered after an input prompt is a string unless we tell it otherwise. Telling the computer
what type of data to expect is called typecasting or casting.
Code: What this code do?
- First, it will ask user to enter first number and
convert number in string into the number in
integer
- Second, it will ask user to enter second
Output: number and convert number in string into the
number in integer
- Next it will total up the number by calling the
variable name.
CHAPTER: PROGRAMMING IN PHYTON
Constants
Sometimes we use the same value more than once in a program. We can avoid having to
type the value each time by specifying constant.

In python, the value of the constant is state at the very beginning of the program and then call
on it when it is needed.

Example:
Constants
pi=3.14
radius=int(input("Enter circle radius: "))
area=pi*radius*radius
print("The circle area is " + str(area))
CHAPTER: PROGRAMMING IN PHYTON
Placeholder
There are another option for combining output other than using concatenation (+). We can
use placeholder.

first_name = input('Enter first name: ')


second_name = input('Enter second name: ')
print ('Hello {0} {1} pleased to meet you’ .format(first_name,second_name))

Place holder can also be used with the input prompt

first_name=input('Enter first name: ')


second_name=input('Enter second name {0} : ' .format(first_name)
print('Hello {0} {1} pleased to meet you'.format(first_name,second_name))
CHAPTER: PROGRAMMING IN PHYTON
List
• A list uses a single identifier/variable to create a container for set of variables.
• The elements in a lists are identified by an index value.
• The first element in a list has the index value 0 .

You might also like