From afe57778c66f61e90cbd3720cc7062e2d7975cbd Mon Sep 17 00:00:00 2001 From: hasanabul Date: Thu, 20 Feb 2014 16:28:59 +0000 Subject: [PATCH 1/2] Create exd34Abul --- exd34Abul | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 exd34Abul diff --git a/exd34Abul b/exd34Abul new file mode 100644 index 0000000..f1701cf --- /dev/null +++ b/exd34Abul @@ -0,0 +1,31 @@ +animals = ['bear', 'python', 'peacock', 'kangaroo', 'whale', 'platypus'] +list(enumerate(animals)) +print "Select 1 for ordinal or 2 for cardinal order. Which option would you like 1 or 2" + +option = raw_input("> ") + +if option == "1": + print "Select ordinal animal position" + + Animal_position = raw_input("> ") + for Animal_position , animals in enumerate(animals): + if Animal_position == 0: + print animals + elif Animal_position == 1: + print animals + elif Animal_position == 2: + print animals + elif Animal_position == 3: + print animals + elif Animal_position == 4: + print animals + elif Animal_position == 5: + print animals + elif Animal_position == 6: + print animals +elif option =="2": + print "Select cardinal animal position" + + +#for animal in animals: + ##print "A animal of type: %s" % animal From 287f48b55e6e0039b857ad4061cb84019429a96e Mon Sep 17 00:00:00 2001 From: hasanabul Date: Thu, 27 Feb 2014 11:11:16 +0000 Subject: [PATCH 2/2] Create dictionaryabul --- dictionaryabul | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 dictionaryabul diff --git a/dictionaryabul b/dictionaryabul new file mode 100644 index 0000000..96dda71 --- /dev/null +++ b/dictionaryabul @@ -0,0 +1,73 @@ +#Create cities abbreviation +Cities = { + 'Greater London': 'GL', + 'Manchester': 'MC', + 'Birmingham': 'BR', + 'Leeds': 'LE', + 'Nottingham': 'NO' +} + + #Create boroughs with cities +Boroughs = { + 'GL': 'Islington', + 'GL': 'Hackney', + 'LE': 'Walton' +} + +Boroughs['NO'] = 'Tower Hamlets' +Boroughs['MC'] = 'Bromley' +#Print out some cities +print '_'*10 +print "England has many boroughs: ", Boroughs['NO'] +print "or ", Boroughs['MC'] +print "These two are not the best boroughs" +print'_'*10 +print "Leeds abbreviation is:", Cities['Leeds'] +print "Nottingham's abbreviation is:", Cities['Nottingham'] +# do it by using the state then cities dict +print'_'*10 +print "Greater London: ", Boroughs[Cities['Greater London']] +print "Greater London: ", Boroughs[Cities['Greater London']]# prints hackney twice +print "Leeds: ", Boroughs[Cities['Leeds']] +#print every cities abbreviation +#the below did not work - yet the one underworked +#print '_' * 10 +#for city, abbrev in Cities.item(): +# print "%s is abbreviated %s" % (city, abbrev) + +print '-' * 10 +for city, abbrev in Cities.items(): + print "%s is abbreviated %s" % (city, abbrev) + #The below did not work either,had to copy and paste from the site +#print '_' * 10 +#for abbrev, Boroughs in Boroughs.item(): + #print "s is has the boroughs %s" % (abbrev, Boroughs) + +print '-' * 10 +for abbrev, Boroughs in Boroughs.items(): + print "%s has the Boroughs %s" % (abbrev, Boroughs) + + ##does not work +#print '-' * 10 +#for city, abbrev in Cities.items(): + # print "%s city is abbreviated %s and has Boroughs %s" % ( + # city, abbrev, Boroughs[abbrev]) + + #print '-' * 10 +#for state, abbrev in states.items(): + # print "%s state is abbreviated %s and has city %s" % ( + #state, abbrev, cities[abbrev]) +# now do both at the same time +#print '-' * 10 +#for city, abbrev in Cities.items(): + # print "%s Cities is abbreviated %s and has Boroughs %s" % ( + #Cities, abbrev, Boroughs[abbrev]) +print '-' * 10 +# safely get a abbreviation by state that might not be there +city = Cities.get('Norwich', None) +if not city: + print "Sorry, no Norwich." +#NOT WORKING +# get a borough with a default value +borough = Boroughs.get('NW', 'Does Not Exist') +print "The borough for the city 'NW' is: %s" % borough