What It Does
This is a program that allows the user to input the name of one of the colleges of Cambridge, such as Clare College for instance, and the year that College was founded, ie 1326, is output.
# Alistair Bhatti # 30/01/2017 names = ["Christ's College","Churchill College","Clare College","Clare Hall", "Corpus Christi College","Darwin College","Downing College", "Emmanuel College","Fitzwilliam College","Girton College", "Gonville & Caius College","Homerton College","Hugh's Hall","Jesus College", "King's College","Lucy Cavendish College","Magdalene College", "Murray Edwards College","Newnham College","Pembroke College","Peterhouse", "Queen's College","Robinson College","Selwyn College","Sidney Sussex College", "St Catharine's College","St Edmunds's College","St John's College", "Trinity College","Trinity Hall","Wolfson College"] lower_names = [i.lower() for i in names] years = ["1505","1960","1326","1965","1352","1964","1800","1584","1869","1869", "1348","1768","1885","1496","1441","1965","1428","1954","1871","1347", "1284","1448","1979","1882","1596","1473","1896","1511","1546","1350", "1965"] def validation(): run = True while run == True: text = input("Plese enter the name of a college.\n").lower() index = find_name(text) if index == None: print("That's not a real College") else: run = False return index def find_name(text_input): term = None for i in range(0, len(names)): if text_input in lower_names[i]: term = i return term def print_details(index): print(names[index]) print("Founded", years[index],"\n") # Main program - loops until keyboard interrupt run = True while run == True: index = validation() print_details(index)
Arrays are clearly not the best way to complete the task and I think that reading them from a .csv file or a Python dictionary (associative array) would have been the more logical and easier way to achieve the same output.
I also feel that the parameter passing and the use of three functions for such a simple program somewhat overcomplicates what is a very simple process, but at least this is good practise, even if the layout is somewhat convoluted. Expect a <em>Bad Code</em> [1.5] in the near future, in which I will try and re-design this program…