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: ")