Advertisement
Adehumble

Week4 Coding Exercise 6

Feb 22nd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #6
  2. print("This program is written to sum the index positions of all the first occurrence of letter 's' in each of your word choice")
  3. print("|||||"*24)
  4.  
  5. #I am going to be demonstrating the functionality of this code by allowing my user to enter the names of his/her secondary school classmates
  6.  
  7.  
  8. #My Function Program
  9. def super_sum(expected_names):
  10.     sum=0
  11.     for name in expected_names:
  12.         if "s" in name:
  13.             sum=sum+name.index("s")
  14.    
  15.     print(sum)
  16.    
  17.  
  18. #My Main Program
  19. user_names=[]
  20. while True:
  21.     try:
  22.         num=int(input("How many students are in your class? "))
  23.         break
  24.     except ValueError:
  25.         print("oopps! That's a wrong input. You must enter a whole integer.\nTry again!")
  26.         print("|||||"*24)
  27. for n in range(num):
  28.     user_name=input("Please, enter the names of your classmates, one after the other: ")
  29.     user_names.append(user_name)
  30. print("The names of your classmates are: ", user_names,"and the sum of all first occurrence of letter 's' is: ")
  31. super_sum(user_names)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement