Adehumble

Week5 Coding Exercise 3

Feb 27th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. #3
  2. #This program is written to return a list of the number of  "a" characters in each choices of a user input
  3.  
  4. #Function Program
  5. def count_of_a(expected_list):
  6.     answer=[]
  7.     for word in expected_list:
  8.         count_a=0
  9.         if "a" in word:
  10.             count_a=word.count("a")
  11.             answer.append(count_a)
  12.         elif "a" not in word:
  13.             answer.append(count_a)
  14.         elif word==" ":
  15.             print(answer)
  16.     print(answer)
  17.            
  18.  
  19. #Main Program
  20. word_list=[]
  21. while True:
  22.     try:
  23.         num=int(input("How many words would you like to play with? "))
  24.         break
  25.     except ValueError:
  26.         print("That's a wrong input!\nYou must provide a positive integer. Please, try again.")
  27.         print("\n")
  28.        
  29. for n in range(num):
  30.     words=input("Enter those words: ")
  31.     word_list.append(words)
  32.  
  33. print("The number of 'a' in each of",word_list, "is: ")
  34. count_of_a(word_list)
Advertisement
Add Comment
Please, Sign In to add comment