SlideShare a Scribd company logo
1 of 16
Brain Storming Techniques For
Logic Development Using Lists
Tuples Strings And Dictionaries
In Python
Brainstorming is an activity
that helps to
What is Brainstorming in Programmming?
• Produce a large number of ideas
• Generate ideas quickly
• Build enthusiasm
• Solve tricky problems
Rules of Brainstorming in Class
Defer judgment
Encourage wild ideas
Build on the ideas of others
Stay focused on the topic
One conversation at a time
Facilitate visual thinking
Go for quantity
Brainstorming
Techniques in
Programming
Mind
Mapping
Brain Writing
Output based
reverse
brainstorming
Dry Run
Working with Python Lists
• Program 1: Take a list of 8 elements. Split it into middle and store the
elements in two different lists.
• Find length of the list.
• Run a loop from first
element till the half
while copying to
another list
• Copy the rest to a third
list
Method 1 Method 2
a=[22,33,44,55,66,77,88,99]
l=len(a)
m=l//2
print(a[:m])
print(a[m:])
Requires 2 loops
Working with Python Lists
• Program : Delete duplicate values from a tuple
X=[1,2,2,3,4,4,5,5,6,
7,8,8]
i=0
while i<len(x):
j=i+1
while j<len(x):
if
x[i]==x[j]:
del(x[j])
j=j+1
i=i+1
print(x)
Method 1 Method 2
x=(1,2,2,3,4,4,5,5,6,7,8,8)
y=list(set(x))
print(y)
Requires nested
loops
The set() method converts any of
the iterable to a distinct sequence
of iterable elements
Zip() :creating a dictionary lookalike from
Tuples
• Program : To group different data values to form tuples.
name=("Preeti", "Asha","Juli", "Kary")
score=(45,34,89,74)
term=("I","II","II","I")
status=("F","F","P","P")
result=zip(name,score,term,status)
print(tuple(result))
Swapping: can be used with all the types
• Program: Names of two students have been swapped. Correct them.
Stud_science="Preeti Mathur"
Stud_commerce="Agastya Gupta"
Stud_science,Stud_commerce=Stud_commerce,Stud_science
print("Sience student is",Stud_science)
print("Commerce Student is ",Stud_commerce)
Palindrome
• Program : To check if a string is a Palindrome or not.
s=input("Enter String")
y=s[::-1]
if s==y:
print("Palindrome")
else:
print("Not Palindrome")
string=input("Enter a String")
k=len(string)
t=k//2
flag=True
i=0
j=k-1
for m in range(t):
if string[i]!=string[j]:
flag=False
i=i+1
j=j-1
if flag==True:
print("Palindrome")
else:
print("Not a Palindrome")
Method 1 Method 2
Join in strings
• Program :Add a space in between all the letters of a string.
s1=input("Enter a String")
s2=" ".join(s1)
print(s2)
Strings and slicing: swapping halves
• Program to swap the first and second half of a string.
str=input("Enter a string")
print(str)
l=len(str)
h=l//2
fh=str[:h]
sh=str[h:]
fh,sh=sh,fh
s=fh + sh
print(s)
Reverse a string
• Program. Input a string and reverse it
str=input("Enter a string")
st=str[::-1]
print(st)
Pattern Printing
• Program: Printing a Pattern of ‘*’.
pattern="*"
for i in range(4):
print(pattern*(i+1))
Alternate elements
• Program : To print alternate elements in a list.
list1=[2,3,5,6,7,8,9]
print(list1[::2])
Creating Dictionaries from input
• Program: Create a record of students with marks in two subjects.
d1=dict()
for i in range(4):
name=input("enter name")
m1=int(input("Enter m1"))
m2=int(input("Enter m2"))
d1[name]=[m1,m2]
print(d1)
• https://www.slideshare.net/NeeruMittal4
To access this presentation and others

More Related Content

Similar to Brain Storming techniques in Python

Programming in Python
Programming in Python Programming in Python
Programming in Python Tiji Thomas
 
python programming for beginners and advanced
python programming for beginners and advancedpython programming for beginners and advanced
python programming for beginners and advancedgranjith6
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Learning with classification and clustering, neural networks
Learning with classification and clustering, neural networksLearning with classification and clustering, neural networks
Learning with classification and clustering, neural networksShaun D'Souza
 
Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptxAshwini Raut
 
Bootcamp Code Notes - Akshansh Chaudhary
Bootcamp Code Notes - Akshansh ChaudharyBootcamp Code Notes - Akshansh Chaudhary
Bootcamp Code Notes - Akshansh ChaudharyAkshansh Chaudhary
 
Python programming computer science and engineering
Python programming computer science and engineeringPython programming computer science and engineering
Python programming computer science and engineeringIRAH34
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Simplilearn
 
Python introduction
Python introductionPython introduction
Python introductionleela rani
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Jean Carlo Machado
 
Introduction to machine_learning
Introduction to machine_learningIntroduction to machine_learning
Introduction to machine_learningKiran Lonikar
 
presentation on data science with python
presentation on data science with pythonpresentation on data science with python
presentation on data science with pythonKhushbujaim
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.supriyasarkar38
 

Similar to Brain Storming techniques in Python (20)

Programming in Python
Programming in Python Programming in Python
Programming in Python
 
python programming for beginners and advanced
python programming for beginners and advancedpython programming for beginners and advanced
python programming for beginners and advanced
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Learning with classification and clustering, neural networks
Learning with classification and clustering, neural networksLearning with classification and clustering, neural networks
Learning with classification and clustering, neural networks
 
Core Concept_Python.pptx
Core Concept_Python.pptxCore Concept_Python.pptx
Core Concept_Python.pptx
 
Bootcamp Code Notes - Akshansh Chaudhary
Bootcamp Code Notes - Akshansh ChaudharyBootcamp Code Notes - Akshansh Chaudhary
Bootcamp Code Notes - Akshansh Chaudhary
 
Python programming computer science and engineering
Python programming computer science and engineeringPython programming computer science and engineering
Python programming computer science and engineering
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
 
Python introduction
Python introductionPython introduction
Python introduction
 
M18 learning
M18 learningM18 learning
M18 learning
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python
 
Prolog 7-Languages
Prolog 7-LanguagesProlog 7-Languages
Prolog 7-Languages
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
 
Introduction to machine_learning
Introduction to machine_learningIntroduction to machine_learning
Introduction to machine_learning
 
presentation on data science with python
presentation on data science with pythonpresentation on data science with python
presentation on data science with python
 
Fp
FpFp
Fp
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
Python basics
Python basicsPython basics
Python basics
 

More from Neeru Mittal

Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptxNeeru Mittal
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python PandasNeeru Mittal
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and TricksNeeru Mittal
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV ConnectivityNeeru Mittal
 
Working of while loop
Working of while loopWorking of while loop
Working of while loopNeeru Mittal
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++Neeru Mittal
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arraysNeeru Mittal
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++Neeru Mittal
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Neeru Mittal
 

More from Neeru Mittal (18)

Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Introduction to AI and its domains.pptx
Introduction to AI and its domains.pptxIntroduction to AI and its domains.pptx
Introduction to AI and its domains.pptx
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
Python Tips and Tricks
Python Tips and TricksPython Tips and Tricks
Python Tips and Tricks
 
Python and CSV Connectivity
Python and CSV ConnectivityPython and CSV Connectivity
Python and CSV Connectivity
 
Working of while loop
Working of while loopWorking of while loop
Working of while loop
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Arrays
ArraysArrays
Arrays
 
Nested loops
Nested loopsNested loops
Nested loops
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Brain Storming techniques in Python

  • 1. Brain Storming Techniques For Logic Development Using Lists Tuples Strings And Dictionaries In Python
  • 2. Brainstorming is an activity that helps to What is Brainstorming in Programmming? • Produce a large number of ideas • Generate ideas quickly • Build enthusiasm • Solve tricky problems
  • 3. Rules of Brainstorming in Class Defer judgment Encourage wild ideas Build on the ideas of others Stay focused on the topic One conversation at a time Facilitate visual thinking Go for quantity
  • 5. Working with Python Lists • Program 1: Take a list of 8 elements. Split it into middle and store the elements in two different lists. • Find length of the list. • Run a loop from first element till the half while copying to another list • Copy the rest to a third list Method 1 Method 2 a=[22,33,44,55,66,77,88,99] l=len(a) m=l//2 print(a[:m]) print(a[m:]) Requires 2 loops
  • 6. Working with Python Lists • Program : Delete duplicate values from a tuple X=[1,2,2,3,4,4,5,5,6, 7,8,8] i=0 while i<len(x): j=i+1 while j<len(x): if x[i]==x[j]: del(x[j]) j=j+1 i=i+1 print(x) Method 1 Method 2 x=(1,2,2,3,4,4,5,5,6,7,8,8) y=list(set(x)) print(y) Requires nested loops The set() method converts any of the iterable to a distinct sequence of iterable elements
  • 7. Zip() :creating a dictionary lookalike from Tuples • Program : To group different data values to form tuples. name=("Preeti", "Asha","Juli", "Kary") score=(45,34,89,74) term=("I","II","II","I") status=("F","F","P","P") result=zip(name,score,term,status) print(tuple(result))
  • 8. Swapping: can be used with all the types • Program: Names of two students have been swapped. Correct them. Stud_science="Preeti Mathur" Stud_commerce="Agastya Gupta" Stud_science,Stud_commerce=Stud_commerce,Stud_science print("Sience student is",Stud_science) print("Commerce Student is ",Stud_commerce)
  • 9. Palindrome • Program : To check if a string is a Palindrome or not. s=input("Enter String") y=s[::-1] if s==y: print("Palindrome") else: print("Not Palindrome") string=input("Enter a String") k=len(string) t=k//2 flag=True i=0 j=k-1 for m in range(t): if string[i]!=string[j]: flag=False i=i+1 j=j-1 if flag==True: print("Palindrome") else: print("Not a Palindrome") Method 1 Method 2
  • 10. Join in strings • Program :Add a space in between all the letters of a string. s1=input("Enter a String") s2=" ".join(s1) print(s2)
  • 11. Strings and slicing: swapping halves • Program to swap the first and second half of a string. str=input("Enter a string") print(str) l=len(str) h=l//2 fh=str[:h] sh=str[h:] fh,sh=sh,fh s=fh + sh print(s)
  • 12. Reverse a string • Program. Input a string and reverse it str=input("Enter a string") st=str[::-1] print(st)
  • 13. Pattern Printing • Program: Printing a Pattern of ‘*’. pattern="*" for i in range(4): print(pattern*(i+1))
  • 14. Alternate elements • Program : To print alternate elements in a list. list1=[2,3,5,6,7,8,9] print(list1[::2])
  • 15. Creating Dictionaries from input • Program: Create a record of students with marks in two subjects. d1=dict() for i in range(4): name=input("enter name") m1=int(input("Enter m1")) m2=int(input("Enter m2")) d1[name]=[m1,m2] print(d1)