USE OF SPLIT() FUNCTION TO READ WORDS AND USING IF CONDITION CHECK THOSE WORDS ARE UPPER,LOWER,VOWELS ETC.
DOWNLOAD YOUTUBE VIDEO:
https://youtu.be/ByKLhofw7jA
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”: