Advertisement
Adehumble

Week4 Coding Exercise 8

Feb 22nd, 2020
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. #8
  2. print("\tThis program is written to return the index position of elements with the same index value in two different list 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 names.of students in two different classes. The program will compare the names in both classes and return the imdex postion of the names having the same index values
  6. #This program is also written to assume equal size/length of both lists
  7.  
  8. #My Function Program
  9. def same_index_values(list1,list2):
  10.     answer=[]
  11.     for m in range(len(list1)):
  12.         if list1[m]==list2[m]:
  13.             answer.append(m)
  14.     print(answer)
  15.  
  16.  
  17. #My Function Program
  18. class1=[]
  19. class2=[]
  20. while True:
  21.     try:
  22.         num=int(input("How many students are in each class? "))
  23.         break
  24.     except ValueError:
  25.         print("Oopss! That's a wrong input.\nYou must enter an integer.\nPlease try again!")
  26. print("||||"*24)       
  27. for q in range(num):
  28.     classes1=input("Enter the names of the students in class1: ")
  29.     class1.append(classes1)
  30.  
  31. print("|||||"*24)
  32. for j in range(num):
  33.     classes2=input("Enter the names of the students in class2: ")
  34.     class2.append(classes2)
  35.    
  36. print("The names of students in class1 are: ",class1)
  37. print("The names of students in class2 are: ",class2)
  38.  
  39. print("The equal index postion is: ")
  40. same_index_values(class1,class2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement