Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions dictionaryabul
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions exd34Abul
Original file line number Diff line number Diff line change
@@ -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):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You ask the user for the value of 'Animal_position' with

Animal_position = raw_intput("> ")

But then this line will throw away the value you've just collected and assign something else

for Animal_position , animals in enumerate(animals):

(as you loop over the enumerate(animals), then Animal_position will be given the values 0 then 1, then 2, then 3.. etc..)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another odd thing you're doing here is starting with

animals = ['bear', 'python', 'peacock', 'kangaroo', 'whale', 'platypus']

but then you are re-assigning animals to have a new value each time around your loop:-

for Animal_position , animals in enumerate(animals):

                          You just gave 'animals' a new value here!

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why bother with the if->elif clauses if they always result in the same thing? why not just do

for Animal_position, animals in enumerate(animals):
print animals

elif option =="2":
print "Select cardinal animal position"


#for animal in animals:
##print "A animal of type: %s" % animal