0% found this document useful (0 votes)
1 views55 pages

G7 Programming

The document provides an overview of programming concepts, focusing on flowcharts, Python programming, and data types. It explains the use of flowcharts for algorithm representation, introduces Python as a high-level language, and covers variable naming conventions, input/output functions, and operators. Additionally, it details control structures like if-else statements and includes examples for better understanding.

Uploaded by

Backup Sahasra
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)
1 views55 pages

G7 Programming

The document provides an overview of programming concepts, focusing on flowcharts, Python programming, and data types. It explains the use of flowcharts for algorithm representation, introduces Python as a high-level language, and covers variable naming conventions, input/output functions, and operators. Additionally, it details control structures like if-else statements and includes examples for better understanding.

Uploaded by

Backup Sahasra
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
You are on page 1/ 55

Programming

Flowchart...

● Graphical representation of an algorithm steps.

● Defined with symbols and arrows.

● Shows steps in sequential order.

● Used in presenting flow of algorithms, or everyday task.


Find out more...

Write other areas where flowchart can be used.


Flowchart Symbols
Symbols Functions
Terminator - Beginning/End of a program.

Process (Any processing/computational function).

Decision (Decision point between two or more paths in a


flowchart).
Data (Represent any type of Input/Output data in a
flowchart).

Connector to show a jump from one point in the process flow


to another.
Flow lines (Shows the direction of flow/ Sequence of
operation)
Flowchart for the sum of two
numbers
Task

Draw a flowchart to calculate the average of five


numbers.
Write the functions of the flowchart symbols given here.
Computer Program
Program is,

❖ A collection of instructions that are executed by the


computer to accomplish a specific result.

❖ Instructions are written in human readable language


called high level language.

❖ Instructions are translated to a computer readable


language called low level language.
Programming Languages
➔ Different ways of writing the same idea.

➔ Each programming language has its own syntax.

➔ Examples are Javascript, Java, Python, etc.

◆ Javascript: alert(“Hello”);

◆ Python: print(“Hello”)

◆ Java: System.out.print(“Hello”);
Introduction to Python Program
❖ Python is a high-level, interpreted, interactive and object-oriented
scripting language. Python is designed to be highly readable.

❖ Created by Guido van Rossum in 1991.


❖ Save the file with “py” extension ex. Hello.py

It is used for:

● web development (server-side),


● software development,
● mathematics,
● system scripting.
Why Python?

● Runs on different platforms (Windows, Mac, Linux, etc).

● Simple syntax similar to the English language.

● Easy to write programs with fewer lines.


Input and Output
❖ Input and Output is the term referred as communication between
a computer program and the user

❖ Input is the term referred as entering data (value) to the


computer program by the user during program execution

❖ Output is the term referred as displaying the data


(value)/information to the user by the computer program.
List the inputs and outputs of these devices.
Output in Python
❖ print() function is often used to display the value/information
to the user by the computer.

print(“Welcome to the Python programming.”)


Simple Welcome Program
Python Online tool
Program
Program -

Output -
Variable
● The identifier (name) given to a memory location used to store the data
(value).

● The data can be changed/assigned during program execution.

● Use variables to set the value which can be using in the program.

● Example : To display name using variable. In this example ‘name’ is


variable.

name = “Geetha”
print(name)
print(“name = “,name)
print(“name=“+name)
Program

Output
Program

Output
Variable
Rules To Name Variable
● Use descriptive names and not use reserved words.
● Only alpha-numeric characters and underscores (A-z, 0-9, and _ ) are
allowed.
● Must start with a letter or the underscore character.
Ex: age, age_12, _total
● Must not start with numbers. Ex: 1num, 1_num.
● Name should not have special characters.
Ex: average@123, books@, @food_items
● Variable names are case-sensitive (age, Age and AGE are three
different variables).
Identify the correct variable name convention in the
following:

● score_total = 56
● @Total = 67
● T = 34
● _age = 12
● age_1 = 23
● print
Answer

● score_total = 56 - Correct
● @Total = 67 - Incorrect (starts with special
characters)
● T = 34 - Incorrect (not descriptive name)
● _age = 12 - Correct
● age_1 = 23 - Correct
● print - Incorrect (Reserved word)
Assign value to variables
Python allows you to assign different values to multiple variables in one
line.
x= "Orange"
y = "Banana"
z = "Cherry"
print(x)
print(y)
print(z]
Assign value to variables
Python allows you to assign different values to multiple variables
in one line.

x, y, z = "Orange", "Banana", "Cherry"

print(x)

print(y)

print(z)
Assign value to variables
You can assign the same value to multiple variables in one
line.

x = y = z = "Orange"

print(x)

print(y)

print(z)
Input Function - Syntax
In python, input function is used to give the data from the user
to the computer program during program execution.

Syntax : input()
Python Comments
❖ Comments are text notes added to the program to provide
explanatory information about the source code
❖ Instructions or Information mentioned within the comments are
considered as “Non-executable” statements (Not executed by the
Python compiler)
❖ Single Line (#) and Multi Line comments (‘’’ ‘’’ – enclosed within
three quotes)
❖ Try out this code and check the output
➢ Single line Comment

#print("Hello, World!")

print("Cheers, Mate!")
Python Data Types
● Data Type is defined as the type (format) of the data in the program.

Data Type Name Data type in Description


Python

Integer int Whole numbers either positive or negative eg:


134

Real (or) Float float Positive or negative decimal values ex: 34.56

Character str Single character or symbol (ex: ‘A’,’$’,’6’)

String str More than one character (ex: “Geetha”, “3.455”,


‘abc@gmail.com’)

Boolean One of two values ‘bool’


either ‘True’ or
‘False’
Python Operators
Arithmetic Operators
● Performs numerical computational tasks.
Addition (+) result = num1 + num2 Add the value in the variables num1, num2
and store it in the result variable.

Subtraction (-) result = num1 - num2 Subtract the value in the variables num1,
num2 and store it in the result variable.

Multiplication result = num1 * num2 Multiply the value in the variables num1,
(*) num2 and store it in the result variable.

Division (/) result = num1 / num2 Divide the value in the variables num1, num2
and store it in the result variable.

Integer (or) result = num1 // num2 Gives quotient value of the division and
Floor Division discards the remainder.
(//)

Modulus (%) Result = num1%num2 Returns only the remainder of the division of
the two numbers.
Program : sum of two numbers

Output
Operator Precedence
Arithmetic Operators - 1

Write a simple program to find the addition, subtraction,


multiplication, division, modulus and integer division of
the two numbers.
Reserved words in Python
Reserved words are case-sensitive in lowercase except None, False, True
and must be used exactly as defined.

False class finally is return

None continue for lambda try

True def from nonlocal while

and del global not with

as elif if or yield

assert else import pass print

break except in raise


Type function

This function gives data type of the variable which holds


string, integer, float values etc.
Task - 1

● Try the following program in Python editor to print the data type of the
variable.
Task - 2

Write a simple program to check the data type of the


integer, real, boolean and character variables.
Program to check the data type of the integer, real, string variable values
Data Type Casting
The process of converting from one data type into another data type.

By default, input function gives user entered value as String data


types.

Type cast functions are,

int( ) - Converts from other data type to integer data type.

float( ) - Converts from other data type to float data type.

str( ) - Converts from other data type to string data type.


What is the output of these programs?

Program 1

Program 2
Output of Program 1

Output of Program 2
Assignment and Arithmetic Operators
Operators Example Description

= c=a+b Assigns value of a+b into c.

+= c+=a Equivalent to c=c+a

-= c-=a Equivalent to c=c-a

*= c*=a Equivalent to c=c*a

/= c/=a Equivalent to c=c/a

//= c//=a Equivalent to c=c//a


Example - Assignment and Arithmetic
Operator

Output
Comparison Operators
== a==b Returns true if a and b are equal, otherwise false.

!= a!=b Returns true if a and b not equal, otherwise false.

< a<b Returns true if a is less than b, otherwise false.

<= a<=b Returns true if a is less than equal to b, otherwise


false.

> a>b Returns true if a is greater than b, otherwise false.

>= a>=b Returns true if a is greater than equal to b, otherwise


false.
Examples - Comparison Operators
Simple - IF Statement Syntax
• IF statement is called as conditional or selection statement.
• Condition is nothing but comparison between two values (or)
between a variable and a value (or) between variables using
comparison operator
• Condition always return boolean value True (or) False.
• If condition is true (satisfied), then it executes statements
defined within the IF block.
• In Python, Indentation is used to define the block of codes to
be executed when the condition is true.
Example for Simple-IF

Output
If-Else Statement Syntax
• If condition is true (satisfied), then it executes statement
defined within the IF block. Otherwise, it executes
statements defined within ELSE block.
• In Python, Indentation is used to define the block of codes
to be executed when the condition is true/false.
Example IF-Else

Output
If-Elif-Else Statement Syntax
• If condition is true (satisfied), then it executes statement
defined within the IF block. Otherwise, it checks the
condition of the followed elif and if it is true it executes
statements defined within, otherwise, ELSE block is
executed.
• We can define as many as elif conditions as per the
requirement. If none of the condition is satisfied, else block
will be executed.
Program to check whether the entered number is a
negative or positive or zero using if-elif-else conditional
structure.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy