python - How do I access the array using the for loop in the while loop -


i working external file has data in form of:

-12345 csee 35000 bart simpson

-12346 csee 25000 harry potter

-12350 economics 30000 krusty clown

-13123 economics 55000 david cameron

with first item being id, second subject, third salary, , rest being name of person.

in part of program trying print information of people have salaries between values submitted user. have put data in list called lecturers put salaries in separate list called lecturers salary , tried make them integers because @ first thought reason loop wasn't working because when trying access them lectures loop thought might still part of string @ point.

i have used loop in program print people teach specific subject. subject submitted user. tried use loop again salaries not working.

print""  # god glory  lecturer = [] lecturer_salary = []  x = 0 = " "  print "" string = raw_input("please enter lecturers details: ") print ""  def printformat(string):     string = string.split()     lastname = string[-1]     firstnames = " ".join(string[3:-1])     name = ", ".join([lastname, firstnames])      id_subject = " ".join(string[0:2])     money = string[2]      print "%s,%s    %s    %s" % (lastname,firstnames,id_subject,money)  printformat(string)   while x < len(lecturer):     lecturer_salary.append(int(lecturer [x][2]))     x = x + 1   print ""  try:       fname = input("enter filename within " ": ")      open(fname) f:         line in f:             data = line.split()             printformat(line)              line = line.split()             lecturer.append(line)           except ioerror e :     print("problem opening file")  print "" print ""    answer = raw_input("would display details of lectureers     particular department please enter yes or no: ")  if answer == "yes" :     print ""     department = raw_input("please enter department: ")     print ""      while x < len(lecturer) :          line in lecturer:              if lecturer[x][1] == department:                 = lecturer[x]                 = ' '.join(a)                 printformat(a)              x = x + 1     **elif answer == "no" :     print ""     answer2 = raw_input ("would know lecturers within particular salary range: ")      print ""      if answer2 ==  "yes":          lower_bound = int(input("please enter lower bound of salary range: "))         upper_bound = int(input("please enter upper bound of salary range: "))          print ""          while x < len(lecturer) :              line in lecturer_salary:                  if lower_bound < lecturer_salary[x] < upper_bound :                      print lecturer_salary[x]                  x = x + 1**   else:     print ""     print "please enter valid input" 

so, have array of lecturer , 1 of lecturer salary. the

for line in lecturer_salary: 

is not needed - while followed if. note print out salary, not lecturer details. since x index both arrays can access lecturer[x] rest. in truth don't need lecturer_salary @ all, walk through lecturer , check:

while x < len(lecturer) :     if lower_bound < lecturer[x][2] < upper_bound :         = lecturer[x]         = ' '.join(a)         printformat(a)     x = x + 1 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -