Algorithm to Generate Grade Ids

For those who would like a program to calculate their grade id, here is one in python:


def prepare_id(id):
  id = id.replace("-", "")
  id = id[len(id)-5:len(id)]
  return int(id)
def gen_id(id, name):
  name = name.lower()
  id = prepare_id(id)
  a = ord('a')
  sum = 0
  for c in name:
    sum = sum + (ord(c) - a) + 1
  return id + sum
if __name__ == '__main__':
  id = '555-65-4321'
  name = 'Palen-Anderson'
  print("The grade id for {} and {} is {}".format(id, name, gen_id(id, name)))
  id = '555-60-1234'
  name = 'Palen Anderson'
  print("The grade id for {} and {} is {}".format(id, name, gen_id(id, name)))


Put this code in a file called gen_id.py and then execute it using the command "python gen_id.py"

The code currently uses the examples from my previous post. You can easily customize the code to generate your particular grade id. Enjoy!

© Kenneth M. Anderson, 2009.