Adehumble

Week4 Coding Exercise 7

Feb 22nd, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. #7
  2. print("\tThis program is written to sum the index positions and their corresponding values in the list of your number choices.\n\tMind you,it will ceaselessly ask you for the proper input of an integer in case you entered a wrong input.\nHappy Coding")
  3. print("|||||"*24)
  4.  
  5. #I am going to be demonstrating the functionality of this code by allowing my user to dynamically provide any range of numbers he/she wishes to play with and their values.
  6.  
  7. #My Function Program
  8. def sum_of_values_and_indices(expected_list):
  9.     indexsum=0
  10.     valuesum=0
  11.     for p in range(len(expected_list)):
  12.         valuesum=valuesum+expected_list[p]
  13.     print(valuesum)
  14.        
  15.    
  16.     for q in expected_list:
  17.         indexsum=indexsum+expected_list.index(q)
  18.         if expected_list.count(q)>1:
  19.             for r in range(1,len(expected_list)):
  20.                 indexsum=indexsum+expected_list.index(q,r)
  21.            
  22.        
  23.        
  24.     print(indexsum)
  25.     print(valuesum+ indexsum)
  26.  
  27.  
  28.  
  29. #My Main Program
  30. numbers=[]
  31. while True:
  32.     try:
  33.         n=int(input("How many numbers do you want to play with? "))
  34.         break
  35.     except ValueError:
  36.         print("Oopss! That's a wrong input.\nYou must enter an integer.\nPlease try again!")
  37.        
  38. for r in range(n):
  39.     while True:
  40.         try:
  41.             num=int(input("enter those numbers: "))
  42.             break
  43.         except ValueError:
  44.             print("Oopss! That's a wrong input.\nYou must enter an integer.\nPlease try again!")
  45.     numbers.append(num)
  46. print(numbers)
  47. sum_of_values_and_indices(numbers)
Add Comment
Please, Sign In to add comment