From 3f50014c8289b6cbc225bfb1df2087e572ac601e Mon Sep 17 00:00:00 2001 From: noglows Date: Mon, 4 Apr 2016 12:25:07 -0700 Subject: [PATCH 1/7] Poverty data completed in Python --- est14_MA.txt | 15 +++++++ est14_WA.txt | 40 +++++++++++++++++++ poverty-processing.py | 91 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 est14_MA.txt create mode 100644 est14_WA.txt create mode 100644 poverty-processing.py diff --git a/est14_MA.txt b/est14_MA.txt new file mode 100644 index 0000000..fd69b49 --- /dev/null +++ b/est14_MA.txt @@ -0,0 +1,15 @@ +25 0 760211 743843 776579 11.7 11.4 12.0 209291 200777 217805 15.3 14.7 15.9 143026 135555 150497 14.2 13.5 14.9 69200 68303 70097 61154 57232 65076 17.1 16.0 18.2 Massachusetts MA est14_MA.txt 06NOV2015 +25 1 18801 15272 22330 8.9 7.2 10.6 4498 3495 5501 13.4 10.4 16.4 3151 2418 3884 12.4 9.5 15.3 64150 61187 67113 Barnstable County MA est14_MA.txt 06NOV2015 +25 3 16037 13403 18671 13.0 10.9 15.1 4543 3669 5417 20.4 16.5 24.3 2974 2341 3607 17.8 14.0 21.6 49890 46940 52840 Berkshire County MA est14_MA.txt 06NOV2015 +25 5 66553 60900 72206 12.4 11.4 13.4 20107 17687 22527 17.4 15.3 19.5 13676 11976 15376 15.8 13.8 17.8 57732 55656 59808 Bristol County MA est14_MA.txt 06NOV2015 +25 7 1544 1199 1889 9.0 7.0 11.0 420 321 519 13.4 10.3 16.5 293 223 363 12.6 9.6 15.6 61259 54940 67578 Dukes County MA est14_MA.txt 06NOV2015 +25 9 80526 73169 87883 10.7 9.7 11.7 25774 22528 29020 15.5 13.6 17.4 17893 15538 20248 14.5 12.6 16.4 70074 68522 71626 Essex County MA est14_MA.txt 06NOV2015 +25 11 8397 7117 9677 12.0 10.2 13.8 2091 1677 2505 16.7 13.4 20.0 1418 1101 1735 15.3 11.9 18.7 53953 50412 57494 Franklin County MA est14_MA.txt 06NOV2015 +25 13 80178 73479 86877 17.7 16.2 19.2 27036 24178 29894 26.2 23.4 29.0 18480 16244 20716 24.3 21.4 27.2 49072 47009 51135 Hampden County MA est14_MA.txt 06NOV2015 +25 15 20809 18436 23182 15.0 13.3 16.7 3078 2491 3665 12.5 10.1 14.9 2099 1686 2512 11.1 8.9 13.3 57737 53688 61786 Hampshire County MA est14_MA.txt 06NOV2015 +25 17 134684 126083 143285 8.9 8.3 9.5 30754 27164 34344 9.6 8.5 10.7 20395 17755 23035 8.8 7.7 9.9 84026 81707 86345 Middlesex County MA est14_MA.txt 06NOV2015 +25 19 765 590 940 7.1 5.5 8.7 184 139 229 8.2 6.2 10.2 124 93 155 8.0 6.0 10.0 82596 75718 89474 Nantucket County MA est14_MA.txt 06NOV2015 +25 21 43999 38525 49473 6.5 5.7 7.3 10459 8628 12290 7.0 5.8 8.2 7565 6219 8911 6.8 5.6 8.0 90039 87658 92420 Norfolk County MA est14_MA.txt 06NOV2015 +25 23 42124 36042 48206 8.5 7.3 9.7 13006 10831 15181 11.5 9.6 13.4 8889 7248 10530 10.3 8.4 12.2 74576 72340 76812 Plymouth County MA est14_MA.txt 06NOV2015 +25 25 155184 146128 164240 21.5 20.2 22.8 41079 37354 44804 31.5 28.6 34.4 28556 25858 31254 32.7 29.6 35.8 54280 52553 56007 Suffolk County MA est14_MA.txt 06NOV2015 +25 27 90611 82565 98657 11.5 10.5 12.5 26263 22963 29563 15.0 13.1 16.9 17513 15063 19963 13.4 11.5 15.3 65217 63662 66772 Worcester County MA est14_MA.txt 06NOV2015 diff --git a/est14_WA.txt b/est14_WA.txt new file mode 100644 index 0000000..77bb19a --- /dev/null +++ b/est14_WA.txt @@ -0,0 +1,40 @@ +53 0 913463 895355 931571 13.2 12.9 13.5 275662 265882 285442 17.5 16.9 18.1 180464 171990 188938 16.0 15.2 16.8 61358 60882 61834 85453 80800 90106 19.6 18.5 20.7 Washington WA est14_WA.txt 06NOV2015 +53 1 3598 2947 4249 19.0 15.6 22.4 1816 1477 2155 27.1 22.0 32.2 1152 903 1401 24.7 19.4 30.0 47423 42474 52372 Adams County WA est14_WA.txt 06NOV2015 +53 3 3573 2849 4297 16.3 13.0 19.6 1104 846 1362 24.2 18.5 29.9 723 546 900 21.5 16.2 26.8 44055 39944 48166 Asotin County WA est14_WA.txt 06NOV2015 +53 5 26893 23628 30158 14.6 12.8 16.4 10421 8839 12003 21.3 18.1 24.5 6754 5615 7893 19.0 15.8 22.2 58750 56072 61428 Benton County WA est14_WA.txt 06NOV2015 +53 7 10298 8470 12126 14.0 11.5 16.5 3588 2774 4402 20.2 15.6 24.8 2436 1839 3033 19.2 14.5 23.9 49174 45028 53320 Chelan County WA est14_WA.txt 06NOV2015 +53 9 11518 9848 13188 16.2 13.8 18.6 3267 2671 3863 26.2 21.4 31.0 2025 1593 2457 22.3 17.5 27.1 47185 43543 50827 Clallam County WA est14_WA.txt 06NOV2015 +53 11 44213 38703 49723 9.9 8.7 11.1 15179 12259 18099 13.6 11.0 16.2 10647 8436 12858 12.8 10.2 15.4 61747 60396 63098 Clark County WA est14_WA.txt 06NOV2015 +53 13 607 469 745 15.5 12.0 19.0 190 145 235 25.7 19.6 31.8 130 98 162 22.0 16.6 27.4 45465 41255 49675 Columbia County WA est14_WA.txt 06NOV2015 +53 15 20701 18425 22977 20.6 18.3 22.9 6118 5100 7136 26.8 22.3 31.3 3909 3166 4652 23.1 18.7 27.5 44235 41355 47115 Cowlitz County WA est14_WA.txt 06NOV2015 +53 17 6120 4978 7262 15.5 12.6 18.4 2507 1974 3040 24.4 19.2 29.6 1712 1339 2085 22.7 17.8 27.6 51151 47257 55045 Douglas County WA est14_WA.txt 06NOV2015 +53 19 1700 1392 2008 22.4 18.3 26.5 403 316 490 29.1 22.8 35.4 264 205 323 25.9 20.1 31.7 39992 36038 43946 Ferry County WA est14_WA.txt 06NOV2015 +53 21 14661 12404 16918 17.3 14.6 20.0 7214 6027 8401 24.9 20.8 29.0 4533 3611 5455 22.4 17.8 27.0 55006 51191 58821 Franklin County WA est14_WA.txt 06NOV2015 +53 23 310 240 380 14.2 11.0 17.4 91 70 112 20.7 15.8 25.6 60 45 75 17.4 13.1 21.7 46404 41508 51300 Garfield County WA est14_WA.txt 06NOV2015 +53 25 14508 11796 17220 15.8 12.8 18.8 5766 4441 7091 20.9 16.1 25.7 3918 2983 4853 20.0 15.2 24.8 50388 47611 53165 Grant County WA est14_WA.txt 06NOV2015 +53 27 13322 11257 15387 19.6 16.6 22.6 4146 3376 4916 28.6 23.3 33.9 2760 2199 3321 26.3 21.0 31.6 43205 40965 45445 Grays Harbor County WA est14_WA.txt 06NOV2015 +53 29 7964 6639 9289 10.3 8.6 12.0 2267 1801 2733 15.4 12.2 18.6 1514 1190 1838 14.7 11.6 17.8 59358 55827 62889 Island County WA est14_WA.txt 06NOV2015 +53 31 4183 3445 4921 14.1 11.6 16.6 972 770 1174 24.5 19.4 29.6 643 502 784 21.8 17.0 26.6 50964 46641 55287 Jefferson County WA est14_WA.txt 06NOV2015 +53 33 230750 218081 243419 11.3 10.7 11.9 58351 52757 63945 13.6 12.3 14.9 38527 34470 42584 12.8 11.5 14.1 75738 74417 77059 King County WA est14_WA.txt 06NOV2015 +53 35 27550 23819 31281 11.2 9.7 12.7 7473 6103 8843 14.4 11.8 17.0 4593 3607 5579 12.2 9.6 14.8 61898 59584 64212 Kitsap County WA est14_WA.txt 06NOV2015 +53 37 7459 6329 8589 18.6 15.8 21.4 1410 1105 1715 18.7 14.7 22.7 953 742 1164 17.6 13.7 21.5 48127 44926 51328 Kittitas County WA est14_WA.txt 06NOV2015 +53 39 3029 2365 3693 14.6 11.4 17.8 935 713 1157 22.6 17.2 28.0 641 481 801 20.9 15.7 26.1 49348 44723 53973 Klickitat County WA est14_WA.txt 06NOV2015 +53 41 12695 10463 14927 17.1 14.1 20.1 3912 3075 4749 24.5 19.3 29.7 2600 2017 3183 22.3 17.3 27.3 44243 40710 47776 Lewis County WA est14_WA.txt 06NOV2015 +53 43 1274 1002 1546 12.5 9.8 15.2 392 303 481 17.7 13.7 21.7 269 207 331 15.7 12.1 19.3 49955 45180 54730 Lincoln County WA est14_WA.txt 06NOV2015 +53 45 9040 7636 10444 15.6 13.2 18.0 2660 2093 3227 23.6 18.6 28.6 1805 1406 2204 22.4 17.4 27.4 52313 49305 55321 Mason County WA est14_WA.txt 06NOV2015 +53 47 9427 8024 10830 23.2 19.8 26.6 2969 2411 3527 31.5 25.6 37.4 1992 1578 2406 29.5 23.4 35.6 37782 34745 40819 Okanogan County WA est14_WA.txt 06NOV2015 +53 49 3606 2929 4283 17.8 14.5 21.1 965 775 1155 28.8 23.1 34.5 674 538 810 28.0 22.4 33.6 40189 36441 43937 Pacific County WA est14_WA.txt 06NOV2015 +53 51 2868 2398 3338 22.3 18.6 26.0 842 665 1019 33.1 26.2 40.0 588 463 713 30.2 23.8 36.6 42579 38373 46785 Pend Oreille County WA est14_WA.txt 06NOV2015 +53 53 106432 97890 114974 13.1 12.1 14.1 34165 30111 38219 17.5 15.4 19.6 22439 19462 25416 16.2 14.1 18.3 60397 58946 61848 Pierce County WA est14_WA.txt 06NOV2015 +53 55 2018 1729 2307 12.7 10.9 14.5 437 351 523 19.6 15.7 23.5 290 227 353 16.7 13.1 20.3 54721 50513 58929 San Juan County WA est14_WA.txt 06NOV2015 +53 57 18627 16409 20845 15.7 13.8 17.6 6124 5231 7017 23.2 19.8 26.6 3765 3106 4424 19.8 16.3 23.3 51395 48709 54081 Skagit County WA est14_WA.txt 06NOV2015 +53 59 1421 1099 1743 12.6 9.7 15.5 467 353 581 20.1 15.2 25.0 316 235 397 17.5 13.0 22.0 52673 47473 57873 Skamania County WA est14_WA.txt 06NOV2015 +53 61 73930 66931 80929 9.9 9.0 10.8 22598 19490 25706 13.1 11.3 14.9 14401 12105 16697 11.5 9.7 13.3 71890 70201 73579 Snohomish County WA est14_WA.txt 06NOV2015 +53 63 76910 70461 83359 16.3 14.9 17.7 21892 18858 24926 20.5 17.7 23.3 13976 11760 16192 18.2 15.3 21.1 50083 48190 51976 Spokane County WA est14_WA.txt 06NOV2015 +53 65 8368 7255 9481 19.3 16.7 21.9 2668 2169 3167 28.2 22.9 33.5 1773 1413 2133 24.5 19.5 29.5 43823 40849 46797 Stevens County WA est14_WA.txt 06NOV2015 +53 67 31197 27796 34598 11.9 10.6 13.2 9031 7502 10560 15.6 13.0 18.2 5706 4551 6861 13.7 10.9 16.5 61653 59047 64259 Thurston County WA est14_WA.txt 06NOV2015 +53 69 558 431 685 13.9 10.7 17.1 184 141 227 26.7 20.4 33.0 130 98 162 24.3 18.3 30.3 51022 48377 53667 Wahkiakum County WA est14_WA.txt 06NOV2015 +53 71 8682 7030 10334 15.7 12.7 18.7 2654 2046 3262 20.8 16.0 25.6 1762 1341 2183 19.1 14.6 23.6 49819 46459 53179 Walla Walla County WA est14_WA.txt 06NOV2015 +53 73 31842 28461 35223 15.7 14.0 17.4 7304 6146 8462 17.7 14.9 20.5 4888 4054 5722 16.4 13.6 19.2 53733 51153 56313 Whatcom County WA est14_WA.txt 06NOV2015 +53 75 11567 10634 12500 28.4 26.1 30.7 1181 938 1424 16.7 13.3 20.1 704 529 879 14.6 11.0 18.2 41837 37907 45767 Whitman County WA est14_WA.txt 06NOV2015 +53 77 50044 45009 55079 20.5 18.4 22.6 22000 19457 24543 30.3 26.8 33.8 14492 12596 16388 28.0 24.3 31.7 44342 42101 46583 Yakima County WA est14_WA.txt 06NOV2015 diff --git a/poverty-processing.py b/poverty-processing.py new file mode 100644 index 0000000..7b1cfb0 --- /dev/null +++ b/poverty-processing.py @@ -0,0 +1,91 @@ +# Take user input for the state + +print "What state would you like to lean about?" +print "Options: 1) Massachusetts, 2) Washington" + +acceptable = False +while acceptable == False: + var = raw_input("Please enter 1 or 2 to make your choice: ") + if var == "1": + print "You have chosen to learn more about Massachusetts" + file = open('est14_MA.txt', 'r') + acceptable = True + elif var == "2": + print "You have chosen to learn more about Washington" + file = open('est14_WA.txt', 'r') + acceptable = True + else: + print "Hmm, that doesn't seem like a valid input. Try again." + +# Initialize tracking variables + +lowest_poverty_county = "" +lowest_youth_poverty = 100 +lowest_median_income = "" +lowest_youth_count = "" +highest_poverty_county = "" +highest_youth_poverty = 0 +highest_median_income = "" +highest_youth_count = "" + +data_dic = {} + + +# Step through each line and keep track of the county with the highest youth poverty rate and the lowest youth poverty rate +for line in file: + if line[3:6].strip() != "0": + all_poverty = line[7:15].strip() + county = line[193:238].strip() + count_youth_poverty = float(line[49:57]) + percent_youth_poverty = float(line[76:80]) + median_household_income = line[133:139].strip() + + if percent_youth_poverty < lowest_youth_poverty: + lowest_poverty_county = county + lowest_youth_poverty = percent_youth_poverty + lowest_youth_count = count_youth_poverty + lowest_median_income = median_household_income + if percent_youth_poverty > highest_youth_poverty: + highest_poverty_county = county + highest_youth_poverty = percent_youth_poverty + highest_youth_count = count_youth_poverty + highest_median_income = median_household_income + + # Keeping track of info for county search + data_dic[county] = [percent_youth_poverty, count_youth_poverty, median_household_income] + +# Print out details on the countys +print "" +print "The county with the highest percentage of children in poverty is " + str(highest_poverty_county) +print "This county has " + str(highest_youth_poverty) + "% of children in poverty." +print "The number of children in poverty is " + str(highest_youth_count) +print "The median household income for this county is " + str(highest_median_income) +print "" +print "The county with the lowest percentage of children in poverty is " + str(lowest_poverty_county) +print "This county has " + str(lowest_youth_poverty) + "% of children in poverty." +print "The number of children in poverty is " + str(lowest_youth_count) +print "The median household income for this county is " + str(lowest_median_income) + +print "Would you like to learn about other counties in this state?" +print "Type 'quit' at any time to exit the program" + +# Loop to handle input of single county and return information on the county +contin = True +while contin == True: + var = raw_input("Enter a county name for more information: ") + if var.lower() == "quit" or var.lower() == "q": + contin = False + else: + var_new = var.lower() + var_new = var_new.replace("county", "") + var_new = var_new.strip().capitalize() + var_new += " County" + if var_new in data_dic.keys(): + print "" + print "You have selected to learn more about " + var_new + print "In " + var_new + ", " + str(data_dic[var_new][0]) + "% of youth live in poverty." + print "The number of children in poverty is " + str(data_dic[var_new][1]) + "." + print "The median household income for this county is " + str(data_dic[var_new][2]) + "." + print "" + else: + print "That doesn't seem to be a valid county name. Try again." From 78719d874ee22645c8c5e6435e27e69a03f593c4 Mon Sep 17 00:00:00 2001 From: noglows Date: Mon, 4 Apr 2016 14:46:30 -0700 Subject: [PATCH 2/7] Spaceships example working in Python --- spaceships-python.py | 135 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 spaceships-python.py diff --git a/spaceships-python.py b/spaceships-python.py new file mode 100644 index 0000000..2b62d1b --- /dev/null +++ b/spaceships-python.py @@ -0,0 +1,135 @@ +class PlanetExpress: + def __init__(self): + self.thirst = 5 + self.work = 5 + self.horde = 5 + self.hunger = 5 + self.receipts = 5 + self.stable = True + + def drink(self): + # decreases thirst and increases work + self.thirst -= 1 + self.work += 1 + + def deliver(self): + # decreases work and increases receipts + self.work -= 1 + self.receipts =+ 1 + + def steal(self): + #increases horde and increases work + self.horde += 1 + self.work += 1 + + def eat(self): + # decreases hunger and increases work + self.hunger -= 1 + self.work += 1 + + def account(self): + # decreases receipts and decreases horde + self.receipts -= 1 + self.horde -= 1 + + def check_stability(self): + if self.thirst > 10 or self.thirst < 0 or self.work > 10 or self.work < 0 or self.horde > 10 or self.horde < 0 or self.hunger > 10 or self.hunger < 0 or self.receipts > 10 or self.receipts < 0: + self.stable = False + + def check(self): + if self.stable == False: + return False + else: + return True + + def score(self): + score = (10-self.thirst) + (10-self.work) + (10-self.hunger) + self.horde + self.receipts + return score + + + +print "Welcome to Planet Express" +print "Let's get started" +print("""\ + /\\ + /''\\ + / \\ + / \\ + / \\ + / \\ + '------------' + |__________| + /----/\----\\ + /| || |\\ + //|____||____|\\\\ + // | || | \\\\ + / | |___||___| | \\ + | | '._||_.' | | + | | |_||_| | | + | | .' || '. | | + | | / || \ | | + | || || || | + | || || || | + | | \ || / | | + | | '. _||_ .' | | + | | _ || _ | | + | |/ \_.'||'._/ \| | + | |\_/ '.||.' \_/| | + | | _||_ | | + /| | .' || '. | |\\ + / '.| / || \ |.' \\ + / ||| || ||| \\ + / ||| || ||| \\ + / || \ || / || \\ + /____/\||__'. _||_ .'__||/\____\\ + |_.--^--||--^--._| + / .'/_'''||'''_\\'. \\ + / / /___||___\ \ \\ + / / /__||__\ \ \\ + / / || \ \\ + /.' || '.\\ + // || \\\\ + __//_ __||__ _\\\__ + '=====' '======' '=====' +""") + +keep_playing = True +game = PlanetExpress() +while keep_playing == True: + success = False + while success == False: + print "You have the following options: drink, deliver, steal, eat, or account" + var = raw_input("What would you like to do? ") + var = var.lower() + if var == "drink": + game.drink() + print "Drink completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "deliver": + game.deliver() + print "Deliver completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "steal": + game.steal() + print "Steal completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "eat": + game.eat() + print "Eat completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "account": + game.account() + print "Account completed successfully" + print "Your current score is " + str(game.score()) + success = True + else: + print "Oops, that didn't seem like one of the options. Try again!" + + game.check() + if game.stable == False: + print "Game Over!" + keep_playing = False From 7c3ac68cf09da4ecd61511c105471ac33b4149b0 Mon Sep 17 00:00:00 2001 From: noglows Date: Mon, 4 Apr 2016 15:02:58 -0700 Subject: [PATCH 3/7] Folder restructuring --- python/poverty-processing.py | 91 +++++++++++++++++++++++ python/spaceships-python.py | 135 +++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 python/poverty-processing.py create mode 100644 python/spaceships-python.py diff --git a/python/poverty-processing.py b/python/poverty-processing.py new file mode 100644 index 0000000..599078b --- /dev/null +++ b/python/poverty-processing.py @@ -0,0 +1,91 @@ +# Take user input for the state + +print "What state would you like to lean about?" +print "Options: 1) Massachusetts, 2) Washington" + +acceptable = False +while acceptable == False: + var = raw_input("Please enter 1 or 2 to make your choice: ") + if var == "1": + print "You have chosen to learn more about Massachusetts" + file = open('../est14_MA.txt', 'r') + acceptable = True + elif var == "2": + print "You have chosen to learn more about Washington" + file = open('../est14_WA.txt', 'r') + acceptable = True + else: + print "Hmm, that doesn't seem like a valid input. Try again." + +# Initialize tracking variables + +lowest_poverty_county = "" +lowest_youth_poverty = 100 +lowest_median_income = "" +lowest_youth_count = "" +highest_poverty_county = "" +highest_youth_poverty = 0 +highest_median_income = "" +highest_youth_count = "" + +data_dic = {} + + +# Step through each line and keep track of the county with the highest youth poverty rate and the lowest youth poverty rate +for line in file: + if line[3:6].strip() != "0": + all_poverty = line[7:15].strip() + county = line[193:238].strip() + count_youth_poverty = float(line[49:57]) + percent_youth_poverty = float(line[76:80]) + median_household_income = line[133:139].strip() + + if percent_youth_poverty < lowest_youth_poverty: + lowest_poverty_county = county + lowest_youth_poverty = percent_youth_poverty + lowest_youth_count = count_youth_poverty + lowest_median_income = median_household_income + if percent_youth_poverty > highest_youth_poverty: + highest_poverty_county = county + highest_youth_poverty = percent_youth_poverty + highest_youth_count = count_youth_poverty + highest_median_income = median_household_income + + # Keeping track of info for county search + data_dic[county] = [percent_youth_poverty, count_youth_poverty, median_household_income] + +# Print out details on the countys +print "" +print "The county with the highest percentage of children in poverty is " + str(highest_poverty_county) +print "This county has " + str(highest_youth_poverty) + "% of children in poverty." +print "The number of children in poverty is " + str(highest_youth_count) +print "The median household income for this county is " + str(highest_median_income) +print "" +print "The county with the lowest percentage of children in poverty is " + str(lowest_poverty_county) +print "This county has " + str(lowest_youth_poverty) + "% of children in poverty." +print "The number of children in poverty is " + str(lowest_youth_count) +print "The median household income for this county is " + str(lowest_median_income) + +print "Would you like to learn about other counties in this state?" +print "Type 'quit' at any time to exit the program" + +# Loop to handle input of single county and return information on the county +contin = True +while contin == True: + var = raw_input("Enter a county name for more information: ") + if var.lower() == "quit" or var.lower() == "q": + contin = False + else: + var_new = var.lower() + var_new = var_new.replace("county", "") + var_new = var_new.strip().capitalize() + var_new += " County" + if var_new in data_dic.keys(): + print "" + print "You have selected to learn more about " + var_new + print "In " + var_new + ", " + str(data_dic[var_new][0]) + "% of youth live in poverty." + print "The number of children in poverty is " + str(data_dic[var_new][1]) + "." + print "The median household income for this county is " + str(data_dic[var_new][2]) + "." + print "" + else: + print "That doesn't seem to be a valid county name. Try again." diff --git a/python/spaceships-python.py b/python/spaceships-python.py new file mode 100644 index 0000000..2b62d1b --- /dev/null +++ b/python/spaceships-python.py @@ -0,0 +1,135 @@ +class PlanetExpress: + def __init__(self): + self.thirst = 5 + self.work = 5 + self.horde = 5 + self.hunger = 5 + self.receipts = 5 + self.stable = True + + def drink(self): + # decreases thirst and increases work + self.thirst -= 1 + self.work += 1 + + def deliver(self): + # decreases work and increases receipts + self.work -= 1 + self.receipts =+ 1 + + def steal(self): + #increases horde and increases work + self.horde += 1 + self.work += 1 + + def eat(self): + # decreases hunger and increases work + self.hunger -= 1 + self.work += 1 + + def account(self): + # decreases receipts and decreases horde + self.receipts -= 1 + self.horde -= 1 + + def check_stability(self): + if self.thirst > 10 or self.thirst < 0 or self.work > 10 or self.work < 0 or self.horde > 10 or self.horde < 0 or self.hunger > 10 or self.hunger < 0 or self.receipts > 10 or self.receipts < 0: + self.stable = False + + def check(self): + if self.stable == False: + return False + else: + return True + + def score(self): + score = (10-self.thirst) + (10-self.work) + (10-self.hunger) + self.horde + self.receipts + return score + + + +print "Welcome to Planet Express" +print "Let's get started" +print("""\ + /\\ + /''\\ + / \\ + / \\ + / \\ + / \\ + '------------' + |__________| + /----/\----\\ + /| || |\\ + //|____||____|\\\\ + // | || | \\\\ + / | |___||___| | \\ + | | '._||_.' | | + | | |_||_| | | + | | .' || '. | | + | | / || \ | | + | || || || | + | || || || | + | | \ || / | | + | | '. _||_ .' | | + | | _ || _ | | + | |/ \_.'||'._/ \| | + | |\_/ '.||.' \_/| | + | | _||_ | | + /| | .' || '. | |\\ + / '.| / || \ |.' \\ + / ||| || ||| \\ + / ||| || ||| \\ + / || \ || / || \\ + /____/\||__'. _||_ .'__||/\____\\ + |_.--^--||--^--._| + / .'/_'''||'''_\\'. \\ + / / /___||___\ \ \\ + / / /__||__\ \ \\ + / / || \ \\ + /.' || '.\\ + // || \\\\ + __//_ __||__ _\\\__ + '=====' '======' '=====' +""") + +keep_playing = True +game = PlanetExpress() +while keep_playing == True: + success = False + while success == False: + print "You have the following options: drink, deliver, steal, eat, or account" + var = raw_input("What would you like to do? ") + var = var.lower() + if var == "drink": + game.drink() + print "Drink completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "deliver": + game.deliver() + print "Deliver completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "steal": + game.steal() + print "Steal completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "eat": + game.eat() + print "Eat completed successfully" + print "Your current score is " + str(game.score()) + success = True + elif var == "account": + game.account() + print "Account completed successfully" + print "Your current score is " + str(game.score()) + success = True + else: + print "Oops, that didn't seem like one of the options. Try again!" + + game.check() + if game.stable == False: + print "Game Over!" + keep_playing = False From ec570789a5d07a8fb0ebfeba53244803f94e1c49 Mon Sep 17 00:00:00 2001 From: noglows Date: Wed, 6 Apr 2016 10:12:32 -0700 Subject: [PATCH 4/7] Initial commit for Spaceships in Javascript --- javascript/spaceships-index.html | 44 +++++++++++++++++ javascript/spaceships-javascript.js | 73 +++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 javascript/spaceships-index.html create mode 100644 javascript/spaceships-javascript.js diff --git a/javascript/spaceships-index.html b/javascript/spaceships-index.html new file mode 100644 index 0000000..e0dc536 --- /dev/null +++ b/javascript/spaceships-index.html @@ -0,0 +1,44 @@ + + + + + + Spaceships + + + +

Planet Express

+ + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyCurrent Level
Fry's Thirst Level
Leela's Unfulfilled Work Orders
Bender's Horde of Treasure
Zoidberg’s Hunger Level
Hermes’s Backlog of Receipts to Process
+ + + + + + + + diff --git a/javascript/spaceships-javascript.js b/javascript/spaceships-javascript.js new file mode 100644 index 0000000..249d794 --- /dev/null +++ b/javascript/spaceships-javascript.js @@ -0,0 +1,73 @@ +function PlanetExpress (max, start) { + this.stable = true; + this.thirst = start; + this.work = start; + this.horde = start; + this.hunger = start; + this.receipts = start; + this.max = max; +} + +PlanetExpress.prototype.drink = function(){ + this.thirst--; + this.work++; +}; + +PlanetExpress.prototype.deliver = function(){ + this.work--; + this.receipts++; +}; + +PlanetExpress.prototype.steal = function(){ + this.horde++; + this.work++; +}; + +PlanetExpress.prototype.eat = function(){ + this.hunger--; + this.work++; +}; + +PlanetExpress.prototype.account = function(){ + this.receipts--; + this.horde--; +}; + +PlanetExpress.prototype.updateLevels = function(){ + $("#thirst").text(planet.thirst); + $("#work").text(planet.work); + $("#horde").text(planet.horde); + $("#hunger").text(planet.hunger); + $("#receipts").text(planet.receipts); +}; + +var planet = new PlanetExpress(10, 5); + +$(document).ready(function(){ + planet.updateLevels(); + + $("#drink").click(function(){ + planet.drink(); + planet.updateLevels(); + }); + + $("#deliver").click(function(){ + planet.deliver(); + planet.updateLevels(); + }); + + $("#steal").click(function(){ + planet.steal(); + planet.updateLevels(); + }); + + $("#eat").click(function(){ + planet.eat(); + planet.updateLevels(); + }); + + $("#account").click(function(){ + planet.account(); + planet.updateLevels(); + }); +}); From 2fe9483b0d10ef719bccd232c47755b761c2c674 Mon Sep 17 00:00:00 2001 From: Jessica Noglows Date: Wed, 6 Apr 2016 10:13:23 -0700 Subject: [PATCH 5/7] Delete poverty-processing.py --- poverty-processing.py | 91 ------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 poverty-processing.py diff --git a/poverty-processing.py b/poverty-processing.py deleted file mode 100644 index 7b1cfb0..0000000 --- a/poverty-processing.py +++ /dev/null @@ -1,91 +0,0 @@ -# Take user input for the state - -print "What state would you like to lean about?" -print "Options: 1) Massachusetts, 2) Washington" - -acceptable = False -while acceptable == False: - var = raw_input("Please enter 1 or 2 to make your choice: ") - if var == "1": - print "You have chosen to learn more about Massachusetts" - file = open('est14_MA.txt', 'r') - acceptable = True - elif var == "2": - print "You have chosen to learn more about Washington" - file = open('est14_WA.txt', 'r') - acceptable = True - else: - print "Hmm, that doesn't seem like a valid input. Try again." - -# Initialize tracking variables - -lowest_poverty_county = "" -lowest_youth_poverty = 100 -lowest_median_income = "" -lowest_youth_count = "" -highest_poverty_county = "" -highest_youth_poverty = 0 -highest_median_income = "" -highest_youth_count = "" - -data_dic = {} - - -# Step through each line and keep track of the county with the highest youth poverty rate and the lowest youth poverty rate -for line in file: - if line[3:6].strip() != "0": - all_poverty = line[7:15].strip() - county = line[193:238].strip() - count_youth_poverty = float(line[49:57]) - percent_youth_poverty = float(line[76:80]) - median_household_income = line[133:139].strip() - - if percent_youth_poverty < lowest_youth_poverty: - lowest_poverty_county = county - lowest_youth_poverty = percent_youth_poverty - lowest_youth_count = count_youth_poverty - lowest_median_income = median_household_income - if percent_youth_poverty > highest_youth_poverty: - highest_poverty_county = county - highest_youth_poverty = percent_youth_poverty - highest_youth_count = count_youth_poverty - highest_median_income = median_household_income - - # Keeping track of info for county search - data_dic[county] = [percent_youth_poverty, count_youth_poverty, median_household_income] - -# Print out details on the countys -print "" -print "The county with the highest percentage of children in poverty is " + str(highest_poverty_county) -print "This county has " + str(highest_youth_poverty) + "% of children in poverty." -print "The number of children in poverty is " + str(highest_youth_count) -print "The median household income for this county is " + str(highest_median_income) -print "" -print "The county with the lowest percentage of children in poverty is " + str(lowest_poverty_county) -print "This county has " + str(lowest_youth_poverty) + "% of children in poverty." -print "The number of children in poverty is " + str(lowest_youth_count) -print "The median household income for this county is " + str(lowest_median_income) - -print "Would you like to learn about other counties in this state?" -print "Type 'quit' at any time to exit the program" - -# Loop to handle input of single county and return information on the county -contin = True -while contin == True: - var = raw_input("Enter a county name for more information: ") - if var.lower() == "quit" or var.lower() == "q": - contin = False - else: - var_new = var.lower() - var_new = var_new.replace("county", "") - var_new = var_new.strip().capitalize() - var_new += " County" - if var_new in data_dic.keys(): - print "" - print "You have selected to learn more about " + var_new - print "In " + var_new + ", " + str(data_dic[var_new][0]) + "% of youth live in poverty." - print "The number of children in poverty is " + str(data_dic[var_new][1]) + "." - print "The median household income for this county is " + str(data_dic[var_new][2]) + "." - print "" - else: - print "That doesn't seem to be a valid county name. Try again." From a24df68969c684662e7cf2a3e1f3ad1cebd5c727 Mon Sep 17 00:00:00 2001 From: Jessica Noglows Date: Wed, 6 Apr 2016 10:13:46 -0700 Subject: [PATCH 6/7] Delete spaceships-python.py --- spaceships-python.py | 135 ------------------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 spaceships-python.py diff --git a/spaceships-python.py b/spaceships-python.py deleted file mode 100644 index 2b62d1b..0000000 --- a/spaceships-python.py +++ /dev/null @@ -1,135 +0,0 @@ -class PlanetExpress: - def __init__(self): - self.thirst = 5 - self.work = 5 - self.horde = 5 - self.hunger = 5 - self.receipts = 5 - self.stable = True - - def drink(self): - # decreases thirst and increases work - self.thirst -= 1 - self.work += 1 - - def deliver(self): - # decreases work and increases receipts - self.work -= 1 - self.receipts =+ 1 - - def steal(self): - #increases horde and increases work - self.horde += 1 - self.work += 1 - - def eat(self): - # decreases hunger and increases work - self.hunger -= 1 - self.work += 1 - - def account(self): - # decreases receipts and decreases horde - self.receipts -= 1 - self.horde -= 1 - - def check_stability(self): - if self.thirst > 10 or self.thirst < 0 or self.work > 10 or self.work < 0 or self.horde > 10 or self.horde < 0 or self.hunger > 10 or self.hunger < 0 or self.receipts > 10 or self.receipts < 0: - self.stable = False - - def check(self): - if self.stable == False: - return False - else: - return True - - def score(self): - score = (10-self.thirst) + (10-self.work) + (10-self.hunger) + self.horde + self.receipts - return score - - - -print "Welcome to Planet Express" -print "Let's get started" -print("""\ - /\\ - /''\\ - / \\ - / \\ - / \\ - / \\ - '------------' - |__________| - /----/\----\\ - /| || |\\ - //|____||____|\\\\ - // | || | \\\\ - / | |___||___| | \\ - | | '._||_.' | | - | | |_||_| | | - | | .' || '. | | - | | / || \ | | - | || || || | - | || || || | - | | \ || / | | - | | '. _||_ .' | | - | | _ || _ | | - | |/ \_.'||'._/ \| | - | |\_/ '.||.' \_/| | - | | _||_ | | - /| | .' || '. | |\\ - / '.| / || \ |.' \\ - / ||| || ||| \\ - / ||| || ||| \\ - / || \ || / || \\ - /____/\||__'. _||_ .'__||/\____\\ - |_.--^--||--^--._| - / .'/_'''||'''_\\'. \\ - / / /___||___\ \ \\ - / / /__||__\ \ \\ - / / || \ \\ - /.' || '.\\ - // || \\\\ - __//_ __||__ _\\\__ - '=====' '======' '=====' -""") - -keep_playing = True -game = PlanetExpress() -while keep_playing == True: - success = False - while success == False: - print "You have the following options: drink, deliver, steal, eat, or account" - var = raw_input("What would you like to do? ") - var = var.lower() - if var == "drink": - game.drink() - print "Drink completed successfully" - print "Your current score is " + str(game.score()) - success = True - elif var == "deliver": - game.deliver() - print "Deliver completed successfully" - print "Your current score is " + str(game.score()) - success = True - elif var == "steal": - game.steal() - print "Steal completed successfully" - print "Your current score is " + str(game.score()) - success = True - elif var == "eat": - game.eat() - print "Eat completed successfully" - print "Your current score is " + str(game.score()) - success = True - elif var == "account": - game.account() - print "Account completed successfully" - print "Your current score is " + str(game.score()) - success = True - else: - print "Oops, that didn't seem like one of the options. Try again!" - - game.check() - if game.stable == False: - print "Game Over!" - keep_playing = False From 704c57c377a4a0052f080a93959777b587b88a7d Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 7 Apr 2016 15:51:00 -0700 Subject: [PATCH 7/7] Code refactoring. Added functions --- python/poverty-processing.py | 86 +++++++++++++++++------------------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/python/poverty-processing.py b/python/poverty-processing.py index 599078b..c083355 100644 --- a/python/poverty-processing.py +++ b/python/poverty-processing.py @@ -1,4 +1,29 @@ -# Take user input for the state +def build_county_dict(lowestfile): + lpc = "" + lowest_youth_poverty = 100 + hpc = "" + highest_youth_poverty = 0 + data_dic = {} + + for line in file: + if line[3:6].strip() != "0": + all_poverty = line[7:15].strip() + county = line[193:238].strip() + count_youth_poverty = float(line[49:57]) + percent_youth_poverty = float(line[76:80]) + median_household_income = line[133:139].strip() + + if percent_youth_poverty < lowest_youth_poverty: + lpc = county + lowest_youth_poverty = percent_youth_poverty + if percent_youth_poverty > highest_youth_poverty: + hpc = county + highest_youth_poverty = percent_youth_poverty + + data_dic[county] = [percent_youth_poverty, count_youth_poverty, median_household_income] + + return data_dic, hpc, lpc + print "What state would you like to lean about?" print "Options: 1) Massachusetts, 2) Washington" @@ -9,62 +34,33 @@ if var == "1": print "You have chosen to learn more about Massachusetts" file = open('../est14_MA.txt', 'r') + data_dic, highest_poverty_county, lowest_poverty_county = build_county_dict(file) + # data_dic = result[0] + # highest_poverty_county = result[1] + # lowest_poverty_county = result[2] acceptable = True elif var == "2": print "You have chosen to learn more about Washington" file = open('../est14_WA.txt', 'r') + result = build_county_dict(file) + data_dic = result[0] + highest_poverty_county = result[1] + lowest_poverty_county = result[2] acceptable = True else: print "Hmm, that doesn't seem like a valid input. Try again." -# Initialize tracking variables - -lowest_poverty_county = "" -lowest_youth_poverty = 100 -lowest_median_income = "" -lowest_youth_count = "" -highest_poverty_county = "" -highest_youth_poverty = 0 -highest_median_income = "" -highest_youth_count = "" - -data_dic = {} - - -# Step through each line and keep track of the county with the highest youth poverty rate and the lowest youth poverty rate -for line in file: - if line[3:6].strip() != "0": - all_poverty = line[7:15].strip() - county = line[193:238].strip() - count_youth_poverty = float(line[49:57]) - percent_youth_poverty = float(line[76:80]) - median_household_income = line[133:139].strip() - - if percent_youth_poverty < lowest_youth_poverty: - lowest_poverty_county = county - lowest_youth_poverty = percent_youth_poverty - lowest_youth_count = count_youth_poverty - lowest_median_income = median_household_income - if percent_youth_poverty > highest_youth_poverty: - highest_poverty_county = county - highest_youth_poverty = percent_youth_poverty - highest_youth_count = count_youth_poverty - highest_median_income = median_household_income - - # Keeping track of info for county search - data_dic[county] = [percent_youth_poverty, count_youth_poverty, median_household_income] - -# Print out details on the countys print "" print "The county with the highest percentage of children in poverty is " + str(highest_poverty_county) -print "This county has " + str(highest_youth_poverty) + "% of children in poverty." -print "The number of children in poverty is " + str(highest_youth_count) -print "The median household income for this county is " + str(highest_median_income) +print "This county has " + str(data_dic[highest_poverty_county][0]) + "% of children in poverty." +print "The number of children in poverty is " + str(data_dic[highest_poverty_county][1]) +print "The median household income for this county is " + str(data_dic[highest_poverty_county][2]) print "" print "The county with the lowest percentage of children in poverty is " + str(lowest_poverty_county) -print "This county has " + str(lowest_youth_poverty) + "% of children in poverty." -print "The number of children in poverty is " + str(lowest_youth_count) -print "The median household income for this county is " + str(lowest_median_income) +print "This county has " + str(data_dic[lowest_poverty_county][0]) + "% of children in poverty." +print "The number of children in poverty is " + str(data_dic[lowest_poverty_county][1]) +print "The median household income for this county is " + str(data_dic[lowest_poverty_county][2]) +print "" print "Would you like to learn about other counties in this state?" print "Type 'quit' at any time to exit the program"