Created
July 16, 2019 15:19
-
-
Save cibofdevs/cd52a494bdaf95b50e90d0eab2c0377a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write code that counts the number of words in 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. | |
# Hard-coded answers will receive no credit. | |
sentence = "python is a high level general purpose programming language that can be applied to many different classes of problems." | |
num_a_or_e = 0 | |
for i in sentence.split(): | |
if ('a' in i) or ('e' in i): | |
num_a_or_e += 1 | |
print(num_a_or_e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sentence = "python is a high level general purpose programming language that can be applied to many different classes of problems."
items = sentence.split(" ")
num_a_or_e=0
print (items)
for y in items:
if (y.count("a"))>0:
num_a_or_e+=1
#print (y)
print (num_a_or_e)
elif (y.count("e"))>0:
num_a_or_e+=1
#print (y)
print (num_a_or_e)