SlideShare une entreprise Scribd logo
1  sur  35
msbacademy.org
Python
Input ,processing and output
msbacademy.org
The Program Development Cycle
Design the
program
Write the
code
Correct
syntax errors
Test the
Program
Correct Logic
Errors
msbacademy.org
Output Statement in Python
print( ) : it display the output on the screen. print() function is
built in function of python.
ex: print(“hello world”)
out put: hello world
msbacademy.org
String and String Literals
String:
a sequence of characters that is used as data is called a string.
String Literals
When a string appears in the actual code of a program
it is called a string literal. In Python code, string literals must be
enclosed in quote marks.
msbacademy.org
Quotes
Quotes are optional in python
Note : 1. use a single quote always in double quotes
2. use a double quote always in triple quotes
msbacademy.org
Comments
Comments in Python start with the hash character, # , and
extend to the end of the physical line.
Example
# This program displays welcome to python programming
Print(“welcome to python programming”)
msbacademy.org
Variable
Variables are nothing but reserved memory locations to store
values. This means that when you create a variable you reserve
some space in memory.
Syntax : Variable=expression
salary=12000
.
msbacademy.org
Variable
Note:
You cannot use a variable until you have assigned a value to it
an error will occur if you try to perform an operation on a variable,
such as printing it, before it has been assigned a value.
msbacademy.org
Variable Naming Rules
Rules:
1. You cannot use one of Python’s key words as a variable
name.
2. A variable name cannot contain spaces.
3. The first character must be one of the letters a through z, A
through Z, or an underscore character (_).
4. After the first character you may use the letters a through z or
A through Z, the digitsb0 through 9, or underscores.
5. Uppercase and lowercase characters are distinct
msbacademy.org
Variable Naming Rules
variable name Legal or Illegal
salary legal
4sum illegal
_abcd legal
while illegal
Max salary illegal
msbacademy.org
Variable Reassignment
Variables are called “variable” because they can reference
different values while a program is running. When you assign a
value to a variable, the variable will reference that value until you
assign it a different value.
msbacademy.org
Variable Reassignment Example
Balance=10000
Print(“my account balance is”,Balance)
Balance=20000
Print(“my account balance is”,Balance)
msbacademy.org
Numeric Data Types and Literals
Numeric Data types
1. Int (When an integer is stored in memory, it is classified as
an int )
2. Float (When a real is stored in memory, it is classified as
a float )
Literals
3.Str (When string literal is stored in memory, it is classified as
a string)
msbacademy.org
Reading Input from the Keyboard
Input(): Python’s built-in input function to read input from the
keyboard.
Syntax:
Variable=input()
Note
it returns string values
msbacademy.org
Reading Numbers with the input Function
Variable=int(input())
Ex: a=int(“enter a value”)
Variable=float(input())
Ex : avg=float(input())
msbacademy.org
Operators
1. Arithmetic Operators
2. Comparison Operators
3. Assignment Operators
4. Logical Operators
5. Membership Operators
6. Identity Operators
msbacademy.org
Arithmetic Operators
Symbol operation
+ Addition
- Subtraction
* Multiplication
/ Division
// Integer division
% Remainder
** Exponent
msbacademy.org
Comparison Operators
Symbol operation
== Equal to
!= Not equal to
<= Less than or equal to
>= Greater than equal to
< Less than
> Greater than equal
msbacademy.org
Assignment Operators
Symbol operation
+= x=x+y is x+=y
-= x=x-y is x-=y
/= x=x/y is x/=y
//= x=x//y is x//=y
%= x=x%y is x%=y
*= x=x+y is x+=y
msbacademy.org
Logical Operators
1. AND
2. OR
3. NOT
msbacademy.org
Logical AND Table
1. (Logical and)
P Q P and Q
T T T
F F F
T F F
F T F
msbacademy.org
Logical OR Table
2. (Logical OR)
P Q P or Q
T T T
F F F
T F T
F T T
msbacademy.org
Logical NOT Operators
3. (Logical NOT)
P not P
T F
F T
msbacademy.org
Membership Operators
1. These operators test for membership in a sequence such as
lists, strings or tuples. There are two membership operators
that are used in Python. (in, not in). It gives the result based
on the variable present in specified sequence or string
msbacademy.org
Identity Operators
1. To compare the memory location of two objects, Identity
Operators are used. The two identify operators used in Python
are (is, is not).
msbacademy.org
Operators Precedence
Operators (Decreasing order
of precedence)
Meaning
** Exponent
*, /, //, % Multiplication, Division, Floor division,
Modulus
+, - Addition, Subtraction
<= < > >= Comparison operators
= %= /= //= -= += *= **= Assignment Operators
is ,is not Identity operators
in not in Membership operators
not or and Logical operators
msbacademy.org
Mixed-Type Expressions and Data Type Conversion
1. When an operation is performed on two int values, the result
will be an int.
2. When an operation is performed on two float values, the result
will be a float
3. When an operation is performed on an int and a float, the int
value will be temporarily converted to a float and the result of
the operation will be a float.
msbacademy.org
Escape Characters
Escape Character Effect
n
t
'
’’

Causes output to be advanced to the next
line
Causes output to skip over to the next
horizontal tab position.
Causes a single quote mark to be printed.
Causes a double quote mark to be printed.
Causes a backslash character to be printed.
msbacademy.org
Formatting Numbers
1. When a floating-point number is displayed by the print
statement, it can appear with up to 12 significant digits.
Ex: toat_marks = 100.0
avg_marks = toat_marks / 3.0
print('Average marks is',avg_marks)
Output: Average marks is 33.3333333333
msbacademy.org
Formatting specifier
format(12345.6789, ‘.2f’)
1. .2 specifies two decimal spaces
2. The f specifies that the data type of the number we are
formatting is a floating-point number.
msbacademy.org
Formatting in Scientific Notation
If you want to display floating-point numbers in scientific
notation, you can use the letter e or the letter E instead of f.
print(format(33.333333333333,’.1e’)
Output
3.3e+1
msbacademy.org
Inserting Comma Separators
1. If you want the number to be formatted with comma
separators, you can insert a comma into the format specifier.
print(format(33333333.3333,’,.2f)
output
33,333,333.33
msbacademy.org
Specifying a Minimum Field Width
1. The format specifier can also include a minimum field width,
which is the minimum number of spaces that should be used
to display the value.
Ex:
print('The number is', format(14586.6889, '12.2f'))
output
The number is 14586.68
msbacademy.org
Formatting Integers
1. You use ‘d’ as the type designator.
2. You cannot specify precision.
Ex :
Print('The number is', format(125465,’,d’))
output
The number is 1,25,465
msbacademy.org
Follow Us:
/msbacademy
/msb academy
/msb_academy
/msb_academy
Thank You

Contenu connexe

Tendances (20)

python Function
python Function python Function
python Function
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
 
Access specifiers(modifiers) in java
Access specifiers(modifiers) in javaAccess specifiers(modifiers) in java
Access specifiers(modifiers) in java
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Files in C
Files in CFiles in C
Files in C
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
stack & queue
stack & queuestack & queue
stack & queue
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 

Similaire à Input processing and output in Python

component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptxAnisZahirahAzman
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input OutputBharat17485
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python BasicsRaghunath A
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2dplunkett
 
TOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfTOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfEjazAlam23
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data TypesTareq Hasan
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| FundamentalsMohd Sajjad
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxKoteswari Kasireddy
 

Similaire à Input processing and output in Python (20)

Python
PythonPython
Python
 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
 
Python programming
Python  programmingPython  programming
Python programming
 
Python basics
Python basicsPython basics
Python basics
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Introduction to Python Basics
Introduction to Python BasicsIntroduction to Python Basics
Introduction to Python Basics
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
 
TOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfTOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdf
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
 
parts_of_python_programming_language.pptx
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
 

Dernier

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Input processing and output in Python