New and Improved
Here’s a drastically modified version of the program that I wrote yesterday, using dictionaries instead of arrays.
# Alistair Bhatti # 31/01/2017 data = {"Christ's College":"1505", "Churchill College":"1960", "Clare College":"1326", "Clare Hall":"1965", "Corpus Christi College":"1352", "Darwin College":"1964", "Downing College":"1800", "Emmanuel College":"1584", "Fitzwilliam College":"1869", "Girton College":"1869", "Gonville & Caius College":"1348", "Homerton College":"1768", "Hugh's Hall":"1885", "Jesus College":"1496", "King's College":"1441", "Lucy Cavendish College":"1965", "Magdalene College":"1428", "Murray Edwards College":"1954", "Newnham College":"1871", "Pembroke College":"1347", "Peterhouse":"1284", "Queen's College":"1448", "Robinson College":"1979", "Selwyn College":"1882", "Sidney Sussex College":"1596", "St Catharine's College":"1473", "St Edmunds's College":"1896", "St John's College":"1511", "Trinity College":"1546", "Trinity Hall":"1350", "Wolfson College":"1965"} def get_info(): while True: text_input = input("Please enter the name of a college, or the year it was founded.\n") text_input = text_input.lower() found = False # Input data compared both the keys and values, and prints every set in which input string appears for i in data.keys(): if text_input in data[i].lower() or text_input in i.lower(): print(i,"was founded in the year", data[i],"\n") found = True if found == False: print("That's not a real college or relevant year\n") # Main Program get_info()
This code is clearly much easier to understand and nicer to look out – I suspect it is subsequently more efficient, as it has fewer functions and no parameter passing.