-
Notifications
You must be signed in to change notification settings - Fork 11
Create exd34Abul #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hasanabul
wants to merge
2
commits into
grahaminn:master
Choose a base branch
from
hasanabul:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Create exd34Abul #11
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): | ||
| 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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): |
||
| elif option =="2": | ||
| print "Select cardinal animal position" | ||
|
|
||
|
|
||
| #for animal in animals: | ||
| ##print "A animal of type: %s" % animal | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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..)
There was a problem hiding this comment.
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):