Skip to content

Instantly share code, notes, and snippets.

@cibofdevs
Created July 16, 2019 15:17
Show Gist options
  • Save cibofdevs/28cb22241ab9f69ebf4b5b1f4121e9e5 to your computer and use it in GitHub Desktop.
Save cibofdevs/28cb22241ab9f69ebf4b5b1f4121e9e5 to your computer and use it in GitHub Desktop.
# Write code to count the number of strings in list items that have the character w in it.
# Assign that number to the variable acc_num.
# HINT 1: Use the accumulation pattern!
# HINT 2: the in operator checks whether a substring is present in a string.
# Hard-coded answers will receive no credit.
items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]
acc_num = 0
for i in items:
if 'w' in i:
acc_num += 1
print(acc_num)
@raviprakashram
Copy link

items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]
acc_num=0
for i in items:
if "w" in i:
acc_num=acc_num+1
print(acc_num)

@Ancalim
Copy link

Ancalim commented Jan 8, 2021

items = ["whirring", "wow!", "calendar", "wry", "glass", "", "llama","tumultuous","owing"]
acc_num=0
for i in items:
if i.count("w"):
acc_num+=1

@pranjaleebokde99
Copy link

pranjaleebokde99 commented Jan 23, 2023

words = sentence.split()
num_a_or_e = 0
for word in words:
if "a" in word[0:]:
print("mujju")
num_a_or_e += 1
elif "e" in word[0:]:
print("mujju")
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