Advertisement
aaka

Python error

Jul 23rd, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. # Dictionary script
  2. # creates a mapping of state to abbreviation
  3. states = [
  4. 'New York' : 'NY',
  5. 'Florida' : 'FL',
  6. 'California' : 'CA',
  7. 'New York' : 'NY',
  8. 'Michigan' : 'MI'
  9. ]
  10. # create a basic set of states and some cities in them
  11. cities = [
  12. 'CA' : 'San Fransico',
  13. 'MI' : 'Detroit',
  14. 'FL' : 'Jacksonville'
  15. ]
  16. # add some more cities
  17. cities['NY'] = 'New York'
  18. cities['OR'] = 'Portland'
  19. # print out some cities
  20. print '_' * 10
  21. print "NY State has: ", cities['NY']
  22. print "OR State has: ", cities['OR']
  23. # print some states
  24. print '_' * 10
  25. print "Michigan's abbreviation is: ", states['Michigan']
  26. print "Florida's abbreviation is: ", states['Florida']
  27. # do it by using the state then cities dict
  28. print '_' * 10
  29. print "Michigan's has: ", cities[states['Michigan']]
  30. print "Florida's has: ", cities[states['Florida']]
  31. # print every state abbreviation
  32. print '_' * 10
  33. for state, abbrev in states.items():
  34. print "%s is abbreviated %s" % (state,abbrev)
  35. # print every city in state
  36. print '_' * 10
  37. for abbrev, city in cities.items():
  38. print " %s has the city %s" % (abbrev,city)
  39. # now do both at the same time
  40. print '_' * 10
  41. for state, abbrev in states.items():
  42. print " %s state is abbreviated %s and has city %s" % (state, abbrev, cities[abbrev])
  43. print '_' * 10
  44. # safely get an abbreviation by state that might not be there
  45. state = states.get('Texas', None)
  46. if not state:
  47. print "Sorry, no taxes."
  48. # get a city with a default value
  49. city = cities.get('TX', 'Does Not Exist')
  50. print "The city for the state 'TX' is : %s" % city
  51.  
  52.  
  53.  
  54.  
  55. ERROR :-
  56. File "ex39.py", line 5
  57. 'New York' : 'NY',
  58. ^
  59. SyntaxError: invalid syntax
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement