SlideShare ist ein Scribd-Unternehmen logo
1 von 4
PYTHON PROGRAMMING
ABSTRACT:
Python is a dynamic, interpreted language.
It’s a computer programming language often
used to build websites and software, automate
tasks, and conduct data analysis. It was
created by Guido Van Rossum in 1991.
INTRODUCTION:
DATA TYPES:
Python data types are used to define the type of
variable. Python has various built-in data types.
• Numeric – int, float, complex
•string - str
•Sequence - list, tuple, range
• Binary - bytes, bytearray, memoryview
• Mapping - dict
• Boolean - bool
• Set - set, frozenset
• None – NoneType
OPERATORS:
Python operators are the constructs which can
manipulate the value of operands.
 Arithmetic Operators
 Comparison (Relational) Operators
 Assignment Operators
• Logical Operators
 Bitwise Operators
 Membership Operators
 Identity Operators
LOOPS:
A loop statement allows us to execute a statement
or group of statements multiple times.
WHILE:
Repeats a statement or group of statements while
a given condition is TRUE. It tests the condition
before executing the loop body.
FOR:
Executes a sequence of statements multiple times
and abbreviates the code that manages the loop
variable.
NESTED:
You can use one or more loop inside any another
while, for or do. while loop.
FUNCTIONS:
A function is a block of organized, reusable code
that is used to perform a single, related action
MODULE:
A module allows you to logically organize your
Python code.
PROGRAM:
Anil is a business man having different
business, among them he also owns a
cloth store. Due to pandemic his sales
are very dull ,to increase the sales and
attract the customers he introduced a
scheme “Lucky Winner” for first 500
customers whose purchases more than
2000rps from their stores will be given a
lottery ticket .Help Anil to Generate 500
random lottery tickets and pick two
lucky tickets from it as a winner.
Note: you must adhere to the following
conditions:
· The lottery number must be 5 digits
long.
· All 500 ticket number must be unique
Algorithm:
◦Create an empty list called “tickets” to
store lottery ticket numbers.
◦While length of tickets list is less than
500.
◦Generate a random 5-digited number,
append it to the list.
◦While checking if it’s unique.
◦Continue iteration until the length of
tickets less than 500.
◦Shuffle the list to randomize the order of
the tickets.
◦Select two tickets at random from the
list as the winner.
◦Print the winning ticket numbers.
CODE:
PROGRAM:
Lapindrome is defined as a string which
when split in the middle, gives two
halvesP having the same characters and
same frequency of each character. If
there are odd number of characters in
the string, we ignore the middle
character and check for lapindrome. For
example gaga is a lapindrome, since the
two halves ga and ga have the same
characters with same frequency.
Algorithm:
•Define lapindrome
•If length of string is even, split into two
equal halves i.e “s1” and “s2”.
•Else split the string into two halves i.e
“s1” and “s2” by ignoring the middle
character.
•Join sorted s1 and s2.
•If s1 is equal to s2.
•Return true, else return false.
CODE:
def is_lapindrome(x):
n=len(x)
if n%2==0:
s1=s[ :n//2]
s2=s[n//2: ]
else:
s1=s[ :n//2]
s2=s[n//2+1: ]
s1=''.join(sorted(s1))
s2=''.join(sorted(s2))
if s1==s2:
return true
else:
return false
x=("enter a string: ")
import random
tickets=set()
while len(tickets)<500:
ticket=random.randint(10000,99999)
tickets.add(ticket)
winners=random.sample(tickets,2)
print("lottery tickets:")
for ticket in tickets:
print(ticket)
print("winners:")
for winner in winners:
print(winner)
if is_lapindrome(x):
print(x,"is a lapindrome")
else:
print(x,"is not lapindrome”)
Basic python programming

Weitere ähnliche Inhalte

Ähnlich wie Basic python programming

Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha BaliAkanksha Bali
 
Advance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learningAdvance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learningsherinjoyson
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizeIruolagbePius
 
Basic Introduction to Python Programming
Basic Introduction to Python ProgrammingBasic Introduction to Python Programming
Basic Introduction to Python ProgrammingSubashiniRathinavel
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problemsRavikiran708913
 
presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxansariparveen06
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfMichpice
 
Introduction to Basics of Python
Introduction to Basics of PythonIntroduction to Basics of Python
Introduction to Basics of PythonElewayte
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdfalaparthi
 
3-Module - Basic Python jUST _ aUTOMATE.pptx.pdf
3-Module - Basic Python  jUST _ aUTOMATE.pptx.pdf3-Module - Basic Python  jUST _ aUTOMATE.pptx.pdf
3-Module - Basic Python jUST _ aUTOMATE.pptx.pdfRajeevPramanik1
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxNimrahafzal1
 

Ähnlich wie Basic python programming (20)

Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
Advance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learningAdvance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learning
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
Variables&DataTypes.pptx
Variables&DataTypes.pptxVariables&DataTypes.pptx
Variables&DataTypes.pptx
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Basic Introduction to Python Programming
Basic Introduction to Python ProgrammingBasic Introduction to Python Programming
Basic Introduction to Python Programming
 
06.pptx
06.pptx06.pptx
06.pptx
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
 
Java session3
Java session3Java session3
Java session3
 
presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptx
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
Introduction to Basics of Python
Introduction to Basics of PythonIntroduction to Basics of Python
Introduction to Basics of Python
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
 
3-Module - Basic Python jUST _ aUTOMATE.pptx.pdf
3-Module - Basic Python  jUST _ aUTOMATE.pptx.pdf3-Module - Basic Python  jUST _ aUTOMATE.pptx.pdf
3-Module - Basic Python jUST _ aUTOMATE.pptx.pdf
 
Python Module-1.1.pdf
Python Module-1.1.pdfPython Module-1.1.pdf
Python Module-1.1.pdf
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 

Kürzlich hochgeladen

Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 

Kürzlich hochgeladen (20)

Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 

Basic python programming

  • 1. PYTHON PROGRAMMING ABSTRACT: Python is a dynamic, interpreted language. It’s a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. It was created by Guido Van Rossum in 1991. INTRODUCTION: DATA TYPES: Python data types are used to define the type of variable. Python has various built-in data types. • Numeric – int, float, complex •string - str •Sequence - list, tuple, range • Binary - bytes, bytearray, memoryview • Mapping - dict • Boolean - bool • Set - set, frozenset • None – NoneType OPERATORS: Python operators are the constructs which can manipulate the value of operands.  Arithmetic Operators  Comparison (Relational) Operators  Assignment Operators • Logical Operators  Bitwise Operators  Membership Operators  Identity Operators LOOPS: A loop statement allows us to execute a statement or group of statements multiple times. WHILE: Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body. FOR: Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. NESTED: You can use one or more loop inside any another while, for or do. while loop. FUNCTIONS: A function is a block of organized, reusable code that is used to perform a single, related action MODULE: A module allows you to logically organize your Python code.
  • 2. PROGRAM: Anil is a business man having different business, among them he also owns a cloth store. Due to pandemic his sales are very dull ,to increase the sales and attract the customers he introduced a scheme “Lucky Winner” for first 500 customers whose purchases more than 2000rps from their stores will be given a lottery ticket .Help Anil to Generate 500 random lottery tickets and pick two lucky tickets from it as a winner. Note: you must adhere to the following conditions: · The lottery number must be 5 digits long. · All 500 ticket number must be unique Algorithm: ◦Create an empty list called “tickets” to store lottery ticket numbers. ◦While length of tickets list is less than 500. ◦Generate a random 5-digited number, append it to the list. ◦While checking if it’s unique. ◦Continue iteration until the length of tickets less than 500. ◦Shuffle the list to randomize the order of the tickets. ◦Select two tickets at random from the list as the winner. ◦Print the winning ticket numbers. CODE: PROGRAM: Lapindrome is defined as a string which when split in the middle, gives two halvesP having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Algorithm: •Define lapindrome •If length of string is even, split into two equal halves i.e “s1” and “s2”. •Else split the string into two halves i.e “s1” and “s2” by ignoring the middle character. •Join sorted s1 and s2. •If s1 is equal to s2. •Return true, else return false. CODE: def is_lapindrome(x): n=len(x) if n%2==0: s1=s[ :n//2] s2=s[n//2: ] else: s1=s[ :n//2] s2=s[n//2+1: ] s1=''.join(sorted(s1)) s2=''.join(sorted(s2)) if s1==s2: return true else: return false x=("enter a string: ")
  • 3. import random tickets=set() while len(tickets)<500: ticket=random.randint(10000,99999) tickets.add(ticket) winners=random.sample(tickets,2) print("lottery tickets:") for ticket in tickets: print(ticket) print("winners:") for winner in winners: print(winner) if is_lapindrome(x): print(x,"is a lapindrome") else: print(x,"is not lapindrome”)