Write code that counts the number of words in
number
sentence that contain either an "a" or an "e". Store the
result in the variable num a or e.
Note 1 be sure to not double-count words that contain both an a and an e.
HINT 1: Use the in operator.
HINT 2 You can either use or or elif
Answers
Answered by
0
Python code that counts the number of words in sentence that contain either an "a" or an "e".
Code:
var=list(str(input("Enter a sentence : ")).split(" "))
count=0
for i in var:
if ('a' in i) and ('e' in i):
continue
if ('a' in i) or ('e' in i):
count+=1
print(count)
Inputs and outputs:
Input 1:
Enter a sentence : Use any sentence
Output 1:
3
Input 2:
Enter a sentence : Hope you are fine.
Output 2:
2
Explanation:
- Take a sentence as an input and split the words in it by a single space and list them.
- Generate a loop that iterates on each word in the list.
- If the word contains both 'a' and 'e' just continue the loop.
- If the word contains either 'e' or 'a', both not both in it, increment count by one.
- Once all the words are in the list are done with checking, print the count.
Learn more :
- Python program to print 1-10 numbers using for loop.
https://brainly.in/question/8287051
- Python program to find area of rectangle, using functions.
https://brainly.in/question/16575685
Attachments:
Answered by
0
- phyton codes that counts the words in the sentence if they are "A" or "E"
Attachments:
Similar questions
English,
5 months ago
Math,
5 months ago
Social Sciences,
5 months ago
Science,
10 months ago
Math,
10 months ago