SlideShare a Scribd company logo
1 of 22
READING WORDS FROM A STRING
COMPUTER SCIENCE
In t his w e d isc uss a bo ut t he reading
wordsfrom a string.
to read word by word from a string
WORDS from the STRINGLet Us First read
Initialize string in a variable nmSTEP 1:
nm=“This Statement wORK FOR READing WORDS from the String in a variable”
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
Use split to break the words and store it
inside another variable and the length.
STEP 2:
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split(): word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
k store the number of words in a variable word. It is 12
0 1 2 3 4 5 6 7 8 9 10 11
Now start the loop first case for read the words
using and for..range/while x start from 0 to k-1
STEP 3:
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split(): word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
Next is display the wordsSTEP 4:
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split(): word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
print(word,end=“”)
print(word[x],end=“”)
print(word[x],end=“”)
Move to next word in loopSTEP 5:
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split(): word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
print(word,end=“”)
print(word[x],end=“”)
print(word[x],end=“”)
x=x+1Increment
automatically
Increment
automatically
This line use for
Incrementing value
So Now You know how to split() and read
words from a string.
Let Us
Solve some of the examples using same format
that we discuss to read words
Q1. Program to count number of words whose length is more than 5 or display those words
whose length is more than 5
Q1. Program to count number of words whose length is more than 5 or display those
words whose length is more than 5
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k):
x=0
while x<k:
print(word,end=“”)
print(word[x],end=“”)
print(word[x],end=“”)
x=x+1
Q1. Program to count number of words whose length is more than 5
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
print(word,end=“”)
print(word[x],end=“”)
print(word[x],end=“”)
x=x+1
First declare variable count=0 to count number of words whose length is more than 5
Q1. Program to count number of words whose length is more than 5
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
print(word,end=“”)
print(word[x],end=“”)
print(word[x],end=“”)
x=x+1
First declare variable count=0 to count number of words whose length is more than 5
Q1. Program to count number of words whose length is more than 5
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
print(word,end=“”)
print(word[x],end=“”)
print(word[x],end=“”)
x=x+1
First declare variable count=0 to count number of words whose length is more than 5
count=0
count=0 count=0
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if len(word) > 5:
x=x+1
Next after for loop place if condition and check the length of the words are more
than 5 or not
count=0
count=0 count=0
if len(word[x]) > 5:
if len(word[x]) > 5:
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if len(word) > 5:
x=x+1
After the if condition placed now put count inside if condition for countingcount
count=0
count=0 count=0
if len(word[x]) > 5:
if len(word[x]) > 5:
count=count+1
count=count+1
count=count+1
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if len(word) > 5:
x=x+1
At last when all the words read and the check by if using len() and counting do no
we need to display how many words length more than 5
count=0
count=0 count=0
if len(word[x]) > 5:
if len(word[x]) > 5:
count=count+1
count=count+1
count=count+1print(“No of words more than 5:”,count)
print(“No of words more than 5:”,count)
print(“No of words more than 5:”,count)
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if len(word) > 5:
x=x+1
count=0
count=0 count=0
if len(word[x]) > 5:
if len(word[x]) > 5:
count=count+1
count=count+1
count=count+1print(“No of words more than 5:”,count)
print(“No of words more than 5:”,count)
print(“No of words more than 5:”,count)
Q1. Program to display of words whose length is more than 5
First in this program remove the line of count=0 and count=count+1
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split(): word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if len(word) > 5:
x=x+1
if len(word[x]) > 5:
if len(word[x]) > 5:
print(“No of words more than 5:”,count)
print(“No of words more than 5:”,count)
print(“No of words more than 5:”,count)
Q1. Program to display of words whose length is more than 5
Now inside the if condition write the print line only and remove the last print
word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
for word in nm.split(): word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if len(word) > 5:
x=x+1
if len(word[x]) > 5:
if len(word[x]) > 5:
print(word)
Q1. Program to display of words whose length is more than 5
Now inside the if condition write the print line only and remove the last print
function also, there is no need of print count.
print(word[x])
print(word[x])
Let Us
discuss some of the examples using same format
that we discuss to read words
Q1. Program to count number of “that” in a string.
Q2. Program to count number of words whose first character is VOWEL.
Q3. Program to count number of words whose first character is UPPERCASE
Q4. Program to count number of words whose first character is LOWERCASE
Q5. Program to copy words whose first character is VOWEL in a another variable.
word=[‘This’,’Statement’,’that’,’FOR’,’READing’,’WORDS’,’that’,’the’,’String’,’that’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement that…..” nm=“This Statement that…..” nm=“This Statement that…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if word in “that”:
x=x+1
if word[x] in “that”:
if word[x] in “that”:
Inside If condition just check using == “that” to check that word exists
Q1. Program to count number of “that” in a string.
count=0
count=0 count=0
count=count+1
print(“No of that::”,count)
count=count+1
print(“No of that::”,count)
count=count+1
print(“No of that::”,count)
word=[‘This’,’Statement’,’that’,’FOR’,’READing’,’WORDS’,’that’,’the’,’String’,’that’,’a’,’variable’]
for….in for….range while ..loop
nm=“This Statement that…..” nm=“This Statement that…..” nm=“This Statement that…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if word “that”:
x=x+1
if word[x] “that”:
if word[x] “that”:
Q1. Program to count number of “that” in a string.
count=0
count=0 count=0
count=count+1
print(“No of that::”,count)
count=count+1
print(“No of that::”,count)
count=count+1
print(“No of that::”,count)
==
==
==
word=[‘This’,’Items’,’that’,’or’,’READing’,’Advance’,’that’,’the’,’String’,’that’,’a’,’variable’]
for….in for….range while ..loop
nm=“This items that…..” nm=“This items that…..” nm=“This items that…..”
for word in nm.split():
word=nm.split()
k=len(word)
word=nm.split()
k=len(word)
for x in range(0,k): x=0
while x<k:
if word[0] in “AEIOUaeiou”:
x=x+1
if word[x][0] in “AEIOUaeiou”:
count=0
count=0 count=0
count=count+1
print(“No of vowel:”,count)
count=count+1
print(“No of vowel:”,count)
count=count+1
print(“No of vowel:”,count)
Q2. Program to count number of words whose first character is VOWEL.
if word[x][0] in “AEIOUaeiou”:

More Related Content

What's hot

Tree Leetcode - Interview Questions - Easy Collections
Tree Leetcode - Interview Questions - Easy CollectionsTree Leetcode - Interview Questions - Easy Collections
Tree Leetcode - Interview Questions - Easy CollectionsSunil Yadav
 
21 properties of division and roots x
21 properties of division and roots x21 properties of division and roots x
21 properties of division and roots xmath260
 
27 power series x
27 power series x27 power series x
27 power series xmath266
 
Class 31: Deanonymizing
Class 31: DeanonymizingClass 31: Deanonymizing
Class 31: DeanonymizingDavid Evans
 
22 double integrals
22 double integrals22 double integrals
22 double integralsmath267
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
String variable in php
String variable in phpString variable in php
String variable in phpchantholnet
 

What's hot (8)

Tree Leetcode - Interview Questions - Easy Collections
Tree Leetcode - Interview Questions - Easy CollectionsTree Leetcode - Interview Questions - Easy Collections
Tree Leetcode - Interview Questions - Easy Collections
 
21 properties of division and roots x
21 properties of division and roots x21 properties of division and roots x
21 properties of division and roots x
 
27 power series x
27 power series x27 power series x
27 power series x
 
Class 31: Deanonymizing
Class 31: DeanonymizingClass 31: Deanonymizing
Class 31: Deanonymizing
 
22 double integrals
22 double integrals22 double integrals
22 double integrals
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
String variable in php
String variable in phpString variable in php
String variable in php
 

Similar to PYTHON-READ WORDS FROM STRING

Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesEelco Visser
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)Pedro Rodrigues
 
Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?
Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?
Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?DoKC
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programaciónSoftware Guru
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Philip Schwarz
 
A guide for teachers – Years 11 and 121 23
A guide for teachers – Years 11 and 121  23 A guide for teachers – Years 11 and 121  23
A guide for teachers – Years 11 and 121 23 mecklenburgstrelitzh
 
A guide for teachers – Years 11 and 121 23 .docx
A guide for teachers – Years 11 and 121  23 .docxA guide for teachers – Years 11 and 121  23 .docx
A guide for teachers – Years 11 and 121 23 .docxmakdul
 
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips  Some hints for approa.docxCSE 220 Assignment 3 Hints and Tips  Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docxfaithxdunce63732
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxcarliotwaycave
 
An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to RakuSimon Proctor
 
Arithmetic sequences and series[1]
Arithmetic sequences and series[1]Arithmetic sequences and series[1]
Arithmetic sequences and series[1]indu psthakur
 
Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...
Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...
Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...HPCC Systems
 

Similar to PYTHON-READ WORDS FROM STRING (18)

Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
 
Word chains
Word chainsWord chains
Word chains
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
 
Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?
Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?
Dok Talks #115 - What More Can I Learn From My OpenTelemetry Traces?
 
Ejercicios de estilo en la programación
Ejercicios de estilo en la programaciónEjercicios de estilo en la programación
Ejercicios de estilo en la programación
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Iteration
IterationIteration
Iteration
 
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
Function Applicative for Great Good of Palindrome Checker Function - Polyglot...
 
A guide for teachers – Years 11 and 121 23
A guide for teachers – Years 11 and 121  23 A guide for teachers – Years 11 and 121  23
A guide for teachers – Years 11 and 121 23
 
A guide for teachers – Years 11 and 121 23 .docx
A guide for teachers – Years 11 and 121  23 .docxA guide for teachers – Years 11 and 121  23 .docx
A guide for teachers – Years 11 and 121 23 .docx
 
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips  Some hints for approa.docxCSE 220 Assignment 3 Hints and Tips  Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
 
java_lect_03-2.ppt
java_lect_03-2.pptjava_lect_03-2.ppt
java_lect_03-2.ppt
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to Raku
 
Arithmetic sequences and series[1]
Arithmetic sequences and series[1]Arithmetic sequences and series[1]
Arithmetic sequences and series[1]
 
Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...
Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...
Using High Dimensional Representation of Words (CBOW) to Find Domain Based Co...
 
Perl intro
Perl introPerl intro
Perl intro
 

More from vikram mahendra

Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemvikram mahendra
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shopvikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMvikram mahendra
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Pythonvikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONvikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONvikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONvikram mahendra
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1vikram mahendra
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONvikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONvikram mahendra
 

More from vikram mahendra (20)

Communication skill
Communication skillCommunication skill
Communication skill
 
Python Project On Cosmetic Shop system
Python Project On Cosmetic Shop systemPython Project On Cosmetic Shop system
Python Project On Cosmetic Shop system
 
Python Project on Computer Shop
Python Project on Computer ShopPython Project on Computer Shop
Python Project on Computer Shop
 
PYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEMPYTHON PROJECT ON CARSHOP SYSTEM
PYTHON PROJECT ON CARSHOP SYSTEM
 
BOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in PythonBOOK SHOP SYSTEM Project in Python
BOOK SHOP SYSTEM Project in Python
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHONFLOW OF CONTROL-NESTED IFS IN PYTHON
FLOW OF CONTROL-NESTED IFS IN PYTHON
 
FLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHONFLOWOFCONTROL-IF..ELSE PYTHON
FLOWOFCONTROL-IF..ELSE PYTHON
 
FLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHONFLOW OF CONTROL-INTRO PYTHON
FLOW OF CONTROL-INTRO PYTHON
 
OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1OPERATOR IN PYTHON-PART1
OPERATOR IN PYTHON-PART1
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
DATA TYPE IN PYTHON
DATA TYPE IN PYTHONDATA TYPE IN PYTHON
DATA TYPE IN PYTHON
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
GREEN SKILL[PART-2]
GREEN SKILL[PART-2]GREEN SKILL[PART-2]
GREEN SKILL[PART-2]
 
GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]GREEN SKILLS[PART-1]
GREEN SKILLS[PART-1]
 
Dictionary in python
Dictionary in pythonDictionary in python
Dictionary in python
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
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
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
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
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
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🔝
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

PYTHON-READ WORDS FROM STRING

  • 1. READING WORDS FROM A STRING COMPUTER SCIENCE
  • 2. In t his w e d isc uss a bo ut t he reading wordsfrom a string. to read word by word from a string WORDS from the STRINGLet Us First read
  • 3. Initialize string in a variable nmSTEP 1: nm=“This Statement wORK FOR READing WORDS from the String in a variable” for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..”
  • 4. Use split to break the words and store it inside another variable and the length. STEP 2: word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) k store the number of words in a variable word. It is 12 0 1 2 3 4 5 6 7 8 9 10 11
  • 5. Now start the loop first case for read the words using and for..range/while x start from 0 to k-1 STEP 3: word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k:
  • 6. Next is display the wordsSTEP 4: word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: print(word,end=“”) print(word[x],end=“”) print(word[x],end=“”)
  • 7. Move to next word in loopSTEP 5: word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: print(word,end=“”) print(word[x],end=“”) print(word[x],end=“”) x=x+1Increment automatically Increment automatically This line use for Incrementing value
  • 8. So Now You know how to split() and read words from a string. Let Us Solve some of the examples using same format that we discuss to read words Q1. Program to count number of words whose length is more than 5 or display those words whose length is more than 5
  • 9. Q1. Program to count number of words whose length is more than 5 or display those words whose length is more than 5 word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: print(word,end=“”) print(word[x],end=“”) print(word[x],end=“”) x=x+1
  • 10. Q1. Program to count number of words whose length is more than 5 word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: print(word,end=“”) print(word[x],end=“”) print(word[x],end=“”) x=x+1 First declare variable count=0 to count number of words whose length is more than 5
  • 11. Q1. Program to count number of words whose length is more than 5 word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: print(word,end=“”) print(word[x],end=“”) print(word[x],end=“”) x=x+1 First declare variable count=0 to count number of words whose length is more than 5
  • 12. Q1. Program to count number of words whose length is more than 5 word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: print(word,end=“”) print(word[x],end=“”) print(word[x],end=“”) x=x+1 First declare variable count=0 to count number of words whose length is more than 5 count=0 count=0 count=0
  • 13. word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if len(word) > 5: x=x+1 Next after for loop place if condition and check the length of the words are more than 5 or not count=0 count=0 count=0 if len(word[x]) > 5: if len(word[x]) > 5:
  • 14. word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if len(word) > 5: x=x+1 After the if condition placed now put count inside if condition for countingcount count=0 count=0 count=0 if len(word[x]) > 5: if len(word[x]) > 5: count=count+1 count=count+1 count=count+1
  • 15. word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if len(word) > 5: x=x+1 At last when all the words read and the check by if using len() and counting do no we need to display how many words length more than 5 count=0 count=0 count=0 if len(word[x]) > 5: if len(word[x]) > 5: count=count+1 count=count+1 count=count+1print(“No of words more than 5:”,count) print(“No of words more than 5:”,count) print(“No of words more than 5:”,count)
  • 16. word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if len(word) > 5: x=x+1 count=0 count=0 count=0 if len(word[x]) > 5: if len(word[x]) > 5: count=count+1 count=count+1 count=count+1print(“No of words more than 5:”,count) print(“No of words more than 5:”,count) print(“No of words more than 5:”,count) Q1. Program to display of words whose length is more than 5 First in this program remove the line of count=0 and count=count+1
  • 17. word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if len(word) > 5: x=x+1 if len(word[x]) > 5: if len(word[x]) > 5: print(“No of words more than 5:”,count) print(“No of words more than 5:”,count) print(“No of words more than 5:”,count) Q1. Program to display of words whose length is more than 5 Now inside the if condition write the print line only and remove the last print
  • 18. word=[‘This’,’Statement’,’wORK’,’FOR’,’READing’,’WORDS’,’from’,’the’,’String’,’in’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement wORK…..” nm=“This Statement wORK…..” nm=“This Statement wORK…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if len(word) > 5: x=x+1 if len(word[x]) > 5: if len(word[x]) > 5: print(word) Q1. Program to display of words whose length is more than 5 Now inside the if condition write the print line only and remove the last print function also, there is no need of print count. print(word[x]) print(word[x])
  • 19. Let Us discuss some of the examples using same format that we discuss to read words Q1. Program to count number of “that” in a string. Q2. Program to count number of words whose first character is VOWEL. Q3. Program to count number of words whose first character is UPPERCASE Q4. Program to count number of words whose first character is LOWERCASE Q5. Program to copy words whose first character is VOWEL in a another variable.
  • 20. word=[‘This’,’Statement’,’that’,’FOR’,’READing’,’WORDS’,’that’,’the’,’String’,’that’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement that…..” nm=“This Statement that…..” nm=“This Statement that…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if word in “that”: x=x+1 if word[x] in “that”: if word[x] in “that”: Inside If condition just check using == “that” to check that word exists Q1. Program to count number of “that” in a string. count=0 count=0 count=0 count=count+1 print(“No of that::”,count) count=count+1 print(“No of that::”,count) count=count+1 print(“No of that::”,count)
  • 21. word=[‘This’,’Statement’,’that’,’FOR’,’READing’,’WORDS’,’that’,’the’,’String’,’that’,’a’,’variable’] for….in for….range while ..loop nm=“This Statement that…..” nm=“This Statement that…..” nm=“This Statement that…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if word “that”: x=x+1 if word[x] “that”: if word[x] “that”: Q1. Program to count number of “that” in a string. count=0 count=0 count=0 count=count+1 print(“No of that::”,count) count=count+1 print(“No of that::”,count) count=count+1 print(“No of that::”,count) == == ==
  • 22. word=[‘This’,’Items’,’that’,’or’,’READing’,’Advance’,’that’,’the’,’String’,’that’,’a’,’variable’] for….in for….range while ..loop nm=“This items that…..” nm=“This items that…..” nm=“This items that…..” for word in nm.split(): word=nm.split() k=len(word) word=nm.split() k=len(word) for x in range(0,k): x=0 while x<k: if word[0] in “AEIOUaeiou”: x=x+1 if word[x][0] in “AEIOUaeiou”: count=0 count=0 count=0 count=count+1 print(“No of vowel:”,count) count=count+1 print(“No of vowel:”,count) count=count+1 print(“No of vowel:”,count) Q2. Program to count number of words whose first character is VOWEL. if word[x][0] in “AEIOUaeiou”: