├── .gitignore ├── README.md └── src ├── cityreader ├── cities.csv ├── cityreader.py ├── test_cityreader.py └── test_stretch.py ├── comp ├── comp.py └── test_comp.py └── oop ├── oop1.py ├── oop2.py ├── test_oop1.py └── test_oop2.py /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | *.sw[op] 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sprint Challenge: Intro to Python 2 | 3 | In this week's Sprint you explored the Python programming language as well as object-oriented design principles. This Sprint Challenge aims to assess your comfort in both of these areas through exercises similar to the ones you worked on at the beginning of this week in Intro to Python. 4 | 5 | ## Instructions 6 | **Read these instructions carefully. Understand exactly what is expected _before_ starting this Sprint Challenge.** 7 | 8 | This is an individual assessment. All work must be your own. Your challenge score is a measure of your ability to work independently using the material covered through this sprint. You need to demonstrate proficiency in the concepts and objectives introduced and practiced in the preceding days. 9 | 10 | You are not allowed to collaborate during the Sprint Challenge. However, you are encouraged to follow the twenty-minute rule and seek support from your PM and Instructor in your cohort help channel on Slack. Your submitted work reflects your proficiency in the concepts and topics that were covered this week. 11 | 12 | You have three hours to complete this Sprint Challenge. Plan your time accordingly. 13 | 14 | ## Commits 15 | 16 | Commit your code regularly and meaningfully. This helps both you (in case you ever need to return to old code for any number of reasons) and it also helps your project manager to more thoroughly assess your work. 17 | 18 | ## Description 19 | 20 | Complete the programs in the `src/` directory in any order. 21 | 22 | * `oop/` 23 | * `oop1.py`: class hierarchies 24 | * `oop2.py`: subclassing and method overriding 25 | * `comp/` 26 | * `comp.py`: list comprehensions 27 | * `cityreader/` 28 | * `cityreader.py`: modules and CSV file reading 29 | 30 | ## Testing 31 | 32 | Each file has its own associated test file. To test your code, run `python [name_of_test_file.py]` or `python3 [name_of_test_file.py]` if your Python 3 command is mapped to `python3`. Note: `cityreader` needs to be run from the same directory as the files or it will not be able to find the associated CSV file. 33 | 34 | The `cityreader` stretch goal has its own test file, `test_stretch.py`, if you want to take a stab at implementing the stretch problem. 35 | 36 | **_It's never a bad idea to take a look at the test files in order to see what each test is expecting._** 37 | 38 | ## Minimum Viable Product 39 | 40 | In order to meet MVP requirements for this Sprint Challenge, complete all of the exercises posed in each directory by getting the tests for each exercise to pass. 41 | 42 | In your solution, it is essential that you follow best practices and produce clean and professional results. Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work. It is better to submit a challenge that meets the MVP requirements than one that attempts too much and does not. 43 | 44 | ## Stretch Problems 45 | 46 | The `cityreader` directory poses an stretch problem that builds upon the functionality you are to implement as part of the non-stretch requirements in the `cityreader` directory. 47 | 48 | There's a separate test file `test_stretch.py` for the stretch problem that you can run in order to test your implementation of the stretch problem. 49 | 50 | ## Rubric 51 | | OBJECTIVE | TASK | 1 - DOES NOT MEET Expectations | 2 - MEETS Expectations | 3 - EXCEEDS Expectations | SCORE | 52 | | ---------- | ----- | ------- | ------- | ------- | -- | 53 | | _Student can demonstrate applied knowledge of Python basics by producing list comprehensions in `comp.py`_ | List Comprehensions: (1 point per problem, 8 max) | 0-5 points | 6-7 points | 8 points | | 54 | | _Student can demonstrate applied knowledge of Object-Oriented Programming by completing `oop1.py` and `oop2.py`_ | OOP: (2 points per file, 4 max) | 0 points | 2 points | 4 points | | 55 | | _Student can demonstrate applied research and language learning by completing `cityreader.py`_ | CSV: 6 points for `cityreader()`, 1 point for `cityreader_stretch()` | 0 points | 6 points | 7 points | | 56 | | **FINAL SCORE** | | **0-13** | **14-18** | **19** | | 57 | -------------------------------------------------------------------------------- /src/cityreader/cities.csv: -------------------------------------------------------------------------------- 1 | city,state_name,county_name,lat,lng,population,density,timezone,zips 2 | Seattle,Washington,King,47.6217,-122.3238,3541236,3243,America/Los_Angeles,98109 98108 98104 98107 98106 98101 98103 98102 98105 98154 98122 98121 98126 98125 98178 98174 98177 98144 98146 98195 98199 98118 98119 98116 98117 98115 98112 98164 98134 98136 98133 98111 98113 98114 98124 98127 98129 98139 98141 98145 98161 98165 98170 98175 98181 98185 98191 98194 3 | Richmond,Virginia,Richmond (city),37.5294,-77.4755,1041877,1440,America/New_York,23219 23222 23223 23220 23221 23226 23227 23224 23225 23230 23235 23234 23173 23218 23232 23241 23242 23249 23255 23260 23261 23269 23273 23274 23276 23278 23279 23282 23284 23285 23286 23288 23289 23290 23291 23292 23293 23295 23297 23298 4 | Virginia Beach,Virginia,Virginia Beach (city),36.7335,-76.0435,1487505,699,America/New_York,23459 23451 23453 23452 23455 23457 23456 23454 23460 23461 23462 23464 23450 23458 23463 23465 23466 23467 23471 23479 5 | Washington,District of Columbia,District of Columbia,38.9047,-77.0163,5191844,4301,America/New_York,20010 20011 20012 20015 20228 20520 20307 20418 20319 20020 20024 20510 20593 20540 20240 20245 20202 20390 20007 20006 20004 20003 20002 20001 20009 20008 20535 20317 20405 20057 20052 20053 20017 20018 20565 20566 20560 20064 20551 20553 20019 20230 20373 20260 20427 20005 20032 20036 20037 20204 20506 20045 20016 20013 20022 20026 20027 20029 20030 20033 20035 20038 20039 20040 20041 20042 20043 20044 20047 20049 20050 20055 20056 20058 20059 20060 20061 20062 20063 20065 20066 20067 20068 20069 20070 20071 20073 20074 20075 20076 20077 20078 20080 20081 20082 20090 20091 20189 20201 20203 20206 20207 20208 20210 20211 20212 20213 20214 20215 20216 20217 20218 20219 20220 20221 20222 20223 20224 20226 20227 20229 20232 20233 20235 20237 20238 20239 20241 20242 20244 20250 20251 20252 20254 20261 20262 20265 20266 20268 20270 20277 20289 20299 20301 20303 20306 20310 20314 20318 20330 20340 20350 20355 20370 20372 20374 20375 20376 20380 20388 20389 20391 20392 20393 20394 20395 20398 20401 20402 20403 20404 20406 20407 20408 20409 20410 20411 20412 20413 20414 20415 20416 20417 20419 20420 20421 20422 20423 20424 20425 20426 20428 20429 20431 20433 20434 20435 20436 20437 20439 20440 20441 20442 20444 20447 20451 20453 20456 20460 20463 20468 20469 20470 20472 20500 20501 20502 20503 20504 20505 20507 20508 20509 20511 20515 20521 20522 20523 20524 20525 20526 20527 20528 20529 20530 20531 20533 20534 20536 20537 20538 20539 20541 20542 20543 20544 20546 20547 20548 20549 20552 20554 20555 20557 20559 20570 20571 20572 20573 20575 20576 20577 20578 20579 20580 20581 20585 20586 20588 20590 20591 20594 20597 20599 56901 56902 56904 56908 56915 56920 56933 56935 56944 56945 56950 56965 56967 56972 56998 56999 6 | Milwaukee,Wisconsin,Milwaukee,43.0640,-87.9669,1377104,2388,America/Chicago,53203 53202 53207 53206 53205 53204 53209 53208 53233 53211 53218 53219 53214 53215 53216 53210 53212 53213 53295 53225 53224 53227 53226 53221 53220 53223 53222 53228 53201 53234 53237 53259 53263 53274 53278 53288 53290 53293 7 | Orlando,Florida,Orange,28.4801,-81.3448,1757288,1041,America/New_York,32829 32827 32824 32822 32804 32805 32806 32807 32801 32803 32808 32839 32835 32832 32819 32812 32811 32814 32802 32816 32834 32853 32854 32855 32856 32857 32858 32859 32860 32861 32862 32867 32868 32869 32872 32877 32878 32885 32886 32887 32891 32897 8 | Miami,Florida,Miami-Dade,25.7840,-80.2102,6247425,4866,America/New_York,33129 33125 33126 33127 33128 33149 33144 33145 33142 33139 33138 33137 33136 33135 33134 33133 33132 33131 33130 33150 33101 33109 33102 33111 33114 33116 33119 33124 33151 33152 33153 33163 33164 33188 33192 33195 33197 33199 33222 33231 33233 33234 33238 33239 33242 33243 33245 33247 33255 33256 33257 33261 33265 33266 33269 33280 33283 33296 33299 9 | Tampa,Florida,Hillsborough,27.9937,-82.4454,2744107,1283,America/New_York,33637 33629 33621 33620 33647 33602 33619 33616 33613 33611 33617 33614 33610 33612 33605 33604 33609 33607 33606 33603 33601 33608 33622 33623 33630 33631 33633 33646 33650 33655 33660 33661 33662 33663 33664 33672 33673 33674 33675 33677 33679 33680 33681 33682 33684 33685 33686 33687 33688 33689 33694 10 | Jacksonville,Florida,Duval,30.3322,-81.6749,1141459,454,America/New_York,32224 32225 32226 32227 32220 32221 32222 32223 32228 32219 32218 32217 32216 32211 32210 32212 32246 32244 32233 32234 32206 32205 32202 32250 32254 32257 32256 32208 32209 32204 32258 32277 32207 32099 32201 32203 32214 32229 32231 32232 32235 32236 32237 32238 32239 32241 32245 32247 32255 32260 11 | Albuquerque,New Mexico,Bernalillo,35.1055,-106.6476,759517,1147,America/Denver,87121 87123 87112 87113 87110 87111 87116 87114 87109 87108 87102 87105 87104 87107 87106 87120 87101 87103 87115 87119 87125 87131 87151 87153 87154 87158 87176 87181 87184 87185 87187 87190 87191 87192 87193 87194 87195 87196 87197 87198 87199 12 | Fort Worth,Texas,Tarrant,32.7813,-97.3466,854113,968,America/Chicago,76164 76040 76134 76135 76137 76131 76132 76133 76109 76108 76105 76104 76107 76103 76102 76155 76106 76053 76052 76123 76120 76244 76006 76008 76179 76177 76036 76140 76262 76127 76118 76119 76116 76117 76114 76115 76112 76110 76111 76129 76101 76113 76121 76122 76124 76130 76136 76147 76150 76161 76162 76163 76166 76181 76185 76191 76192 76193 76195 76196 76197 76198 76199 13 | McAllen,Texas,Hidalgo,26.2203,-98.2457,798187,1113,America/Chicago,78504 78503 78501 78502 78505 14 | El Paso,Texas,El Paso,31.8478,-106.4310,845059,1027,America/Denver,79901 79902 79903 79904 79905 79906 79907 79930 79932 79935 79934 79936 79912 79911 79835 79922 79920 79927 79924 79925 79915 79910 79913 79914 79917 79918 79923 79926 79929 79931 79937 79940 79941 79943 79944 79945 79946 79947 79948 79949 79950 79951 79952 79953 79954 79955 79958 79960 79961 79968 79976 79978 79980 79995 79996 79997 79998 79999 88510 88511 88512 88513 88514 88515 88517 88518 88519 88520 88521 88523 88524 88525 88526 88527 88528 88529 88530 88531 88532 88533 88534 88535 88536 88538 88539 88540 88541 88542 88543 88544 88545 88546 88547 88548 88549 88550 88553 88554 88555 88556 88557 88558 88559 88560 88561 88562 88563 88565 88566 88567 88568 88569 88570 88571 88572 88573 88574 88575 88576 88577 88578 88579 88580 88581 88582 88583 88584 88585 88586 88587 88588 88589 88590 88595 15 | Dallas,Texas,Dallas,32.7938,-96.7659,5634307,1490,America/Chicago,75287 75098 75233 75231 75234 75254 75251 75252 75253 75032 75227 75238 75232 75230 75236 75237 75235 75088 75087 75243 75247 75244 75249 75248 75051 75210 75211 75212 75214 75215 75216 75217 75218 75219 75390 75182 75229 75228 75220 75223 75225 75224 75226 75241 75240 75246 75043 75166 75270 75207 75206 75205 75204 75203 75202 75201 75209 75208 75019 75221 75222 75242 75250 75260 75261 75262 75263 75264 75265 75266 75267 75275 75277 75283 75284 75285 75301 75303 75312 75313 75315 75320 75326 75336 75339 75342 75354 75355 75356 75357 75358 75359 75360 75367 75368 75370 75371 75372 75373 75374 75376 75378 75379 75380 75381 75382 75389 75391 75392 75393 75394 75395 75397 75398 16 | Austin,Texas,Travis,30.3038,-97.7545,1633847,1170,America/Chicago,78749 78748 78741 78742 78745 78744 78747 78746 78717 78712 78719 78617 78739 78735 78730 78731 78732 78733 78705 78704 78701 78703 78702 78758 78759 78752 78753 78750 78751 78756 78757 78754 78652 78723 78722 78721 78727 78726 78725 78724 78729 78728 73301 73344 78651 78708 78709 78710 78711 78713 78714 78715 78716 78718 78720 78755 78760 78761 78762 78763 78764 78765 78766 78767 78768 78769 78772 78773 78774 78778 78779 78783 78799 17 | Houston,Texas,Harris,29.7871,-95.3936,5424720,1412,America/Chicago,77069 77068 77061 77060 77063 77062 77065 77064 77067 77066 77346 77036 77037 77034 77035 77032 77033 77030 77031 77038 77449 77489 77046 77044 77040 77048 77201 77598 77018 77019 77015 77016 77017 77010 77011 77012 77013 77092 77093 77345 77546 77080 77025 77024 77027 77026 77021 77020 77023 77022 77029 77028 77094 77096 77090 77091 77098 77099 77078 77079 77072 77073 77070 77071 77076 77077 77074 77075 77407 77047 77045 77043 77041 77336 77339 77338 77003 77002 77007 77006 77005 77004 77009 77008 77450 77084 77089 77088 77083 77082 77081 77087 77086 77085 77042 77053 77054 77055 77056 77057 77058 77059 77396 77050 77051 77504 77001 77052 77202 77203 77204 77205 77206 77207 77208 77209 77210 77212 77213 77215 77216 77217 77218 77219 77220 77221 77222 77223 77224 77225 77226 77227 77228 77229 77230 77231 77233 77234 77235 77236 77237 77238 77240 77241 77242 77243 77244 77245 77248 77249 77251 77252 77253 77254 77255 77256 77257 77258 77259 77261 77262 77263 77265 77266 77267 77268 77269 77270 77271 77272 77273 77274 77275 77277 77279 77280 77282 77284 77287 77288 77289 77290 77291 77292 77293 77297 77299 77315 77411 18 | San Antonio,Texas,Bexar,29.4722,-98.5247,1976787,1250,America/Chicago,78112 78233 78259 78258 78252 78251 78250 78257 78256 78255 78254 78208 78201 78202 78203 78204 78205 78207 78231 78230 78232 78235 78234 78237 78239 78238 78209 78109 78266 78260 78219 78218 78217 78216 78215 78214 78213 78212 78211 78210 78244 78245 78247 78240 78242 78248 78249 78023 78222 78223 78220 78221 78226 78227 78224 78225 78228 78229 78054 78206 78241 78246 78265 78268 78269 78270 78278 78279 78280 78283 78284 78285 78288 78289 78291 78292 78293 78294 78295 78296 78297 78298 78299 19 | New Orleans,Louisiana,Orleans,30.0687,-89.9288,1024421,892,America/Chicago,70139 70130 70131 70114 70115 70116 70117 70112 70113 70118 70119 70129 70128 70125 70124 70127 70126 70122 70163 70141 70142 70143 70145 70146 70148 70150 70151 70152 70153 70154 70156 70157 70158 70159 70160 70161 70162 70164 70165 70166 70167 70170 70172 70174 70175 70176 70177 70178 70179 70181 70182 70183 70184 70185 70186 70187 70189 70190 70195 20 | Charlotte,North Carolina,Mecklenburg,35.2080,-80.8308,1438351,1065,America/New_York,28269 28262 28105 28280 28282 28209 28208 28205 28204 28207 28206 28203 28202 28227 28226 28278 28270 28273 28277 28134 28216 28217 28214 28215 28212 28213 28210 28211 28244 28126 28130 28201 28218 28219 28220 28221 28222 28223 28224 28228 28229 28230 28231 28232 28233 28234 28235 28236 28237 28241 28242 28243 28246 28247 28253 28254 28255 28256 28258 28260 28263 28265 28266 28271 28272 28274 28275 28281 28284 28285 28287 28288 28289 28290 28296 28297 28299 21 | Raleigh,North Carolina,Wake,35.8323,-78.6441,1005457,1225,America/New_York,27617 27616 27615 27614 27613 27612 27610 27608 27609 27601 27603 27604 27605 27606 27607 27602 27611 27619 27620 27621 27622 27623 27624 27625 27626 27627 27628 27629 27634 27635 27636 27640 27650 27656 27658 27661 27668 27675 27676 27690 27695 27697 27698 27699 22 | Omaha,Nebraska,Douglas,41.2634,-96.0453,792463,1295,America/Chicago,68116 68118 68106 68107 68105 68108 68178 68111 68122 68127 68124 68110 68112 68114 68117 68022 68132 68144 68137 68135 68134 68131 68130 68102 68104 68164 68152 68154 68101 68103 68109 68119 68139 68145 68172 68175 68176 68179 68180 68182 68183 68198 23 | Memphis,Tennessee,Shelby,35.1047,-89.9773,1069661,794,America/Chicago,38122 38125 38127 38107 38106 38105 38104 38103 38109 38108 38152 38132 38133 38131 38141 38111 38112 38114 38115 38116 38117 38118 38119 38018 38016 38134 38128 38120 38126 37501 37544 38101 38113 38124 38130 38136 38137 38145 38148 38150 38151 38157 38159 38161 38163 38166 38167 38168 38173 38174 38175 38177 38181 38182 38184 38186 38187 38188 38190 38193 38194 38197 24 | Nashville,Tennessee,Davidson,36.1714,-86.7844,1065078,535,America/Chicago,37027 37138 37076 37072 37201 37203 37206 37240 37243 37246 37080 37218 37219 37216 37217 37214 37215 37212 37213 37210 37211 37189 37209 37208 37205 37204 37207 37115 37013 37228 37221 37220 37143 37011 37116 37202 37222 37224 37227 37229 37230 37232 37234 37235 37236 37238 37241 37242 37244 37250 25 | Buffalo,New York,Erie,42.9016,-78.8487,920136,2456,America/New_York,14208 14209 14202 14203 14201 14206 14207 14204 14220 14222 14218 14211 14210 14213 14212 14215 14214 14216 14205 14231 14233 14240 14241 14260 14263 14264 14265 14267 14269 14270 14272 14273 14276 14280 26 | Queens,New York,Queens,40.7498,-73.7976,2333054,8247,America/New_York,11361 11362 11363 11364 11354 11355 11356 11357 11358 11359 11360 11365 11366 11367 11412 11423 11432 11433 11434 11435 11436 11101 11102 11103 11104 11105 11106 11374 11375 11379 11385 11691 11692 11693 11694 11695 11697 11004 11005 11411 11413 11422 11426 11427 11428 11429 11414 11415 11416 11417 11418 11419 11420 11421 11368 11369 11370 11372 11373 11377 11378 27 | New York,New York,New York,40.6943,-73.9249,19164071,10934,America/New_York,11229 11226 11225 11224 11222 11221 11220 11385 10169 10168 10167 10165 10162 10282 10280 10040 10044 11109 11102 11103 11104 11105 11379 11378 11697 11694 11692 11693 11691 10271 10279 10278 10075 10302 10452 11451 10475 10474 10471 10470 10473 10472 11228 11223 10103 11368 11369 11366 11367 11365 11362 11363 11360 11361 10028 10029 10026 10027 10024 10025 10022 10023 10020 10021 11212 11213 11210 11211 11216 11217 11214 11215 11218 11219 10152 10153 10154 10306 10305 10310 10311 10312 10314 11432 11433 11430 11436 11434 11435 10453 10451 10457 10456 10455 10454 10459 10458 10128 10004 10005 10006 10007 10001 10002 10003 10009 11238 11239 11230 11231 11232 11233 11234 11235 11236 11237 11375 11374 11377 11371 11370 11373 11372 10170 10171 10172 10173 10174 10177 11351 10039 10038 10035 10034 10037 10036 10031 10030 10033 10032 11201 11208 11203 11205 11204 11207 11206 11209 11411 11412 11413 11414 11415 11416 11417 11418 11419 11101 11106 11001 11005 11004 10065 10069 10199 10309 10308 10307 10304 10303 10301 11429 11428 11421 11420 11423 11422 11425 11424 11427 11426 10466 10467 10464 10465 10462 10463 10460 10461 10468 10469 10119 10115 10112 10110 10111 11364 11359 11358 11357 11356 11355 11354 10019 10018 10013 10012 10011 10010 10017 10016 10014 10008 10041 10043 10045 10055 10060 10080 10081 10087 10090 10101 10102 10104 10105 10106 10107 10108 10109 10113 10114 10116 10117 10118 10120 10121 10122 10123 10124 10125 10126 10129 10130 10131 10132 10133 10138 10150 10151 10155 10156 10157 10158 10159 10160 10163 10164 10166 10175 10176 10178 10179 10185 10203 10211 10212 10213 10242 10249 10256 10258 10259 10260 10261 10265 10268 10269 10270 10272 10273 10274 10275 10276 10277 10281 10285 10286 10313 11120 11202 11241 11242 11243 11245 11247 11249 11251 11252 11256 11352 11380 11381 11386 11405 11431 11439 11499 11690 11695 28 | Bronx,New York,Bronx,40.8501,-73.8662,1455720,13202,America/New_York,10453 10457 10460 10458 10467 10468 10451 10452 10456 10454 10455 10459 10474 10463 10471 10466 10469 10470 10475 10461 10462 10464 10465 10472 10473 29 | Brooklyn,New York,Kings,40.6501,-73.9496,2629150,14606,America/New_York,11212 11213 11216 11233 11238 11209 11214 11228 11204 11218 11219 11230 11234 11236 11239 11223 11224 11229 11235 11201 11205 11215 11217 11231 11203 11210 11225 11226 11207 11208 11211 11222 11220 11232 11206 11221 11237 30 | Manhattan,New York,New York,40.7834,-73.9662,1643734,27799,America/New_York,10026 10027 10030 10037 10039 10001 10011 10018 10019 10020 10036 10029 10035 10010 10016 10017 10022 10012 10013 10014 10004 10005 10006 10007 10038 10280 10002 10003 10009 10021 10028 10044 10065 10075 10128 10023 10024 10025 10031 10032 10033 10034 10040 31 | Philadelphia,Pennsylvania,Philadelphia,40.0076,-75.1340,5591554,4511,America/New_York,19154 19151 19150 19153 19152 19102 19103 19106 19107 19104 19109 19128 19129 19120 19121 19122 19123 19124 19125 19126 19127 19112 19111 19115 19114 19116 19119 19118 19148 19149 19146 19147 19144 19145 19142 19143 19140 19141 19139 19138 19137 19136 19135 19134 19133 19132 19131 19130 19019 19092 19093 19099 19101 19105 19108 19110 19155 19160 19161 19162 19170 19171 19172 19173 19175 19176 19177 19178 19179 19181 19182 19183 19184 19185 19187 19188 19190 19191 19192 19193 19194 19195 19196 19197 19244 19255 32 | Pittsburgh,Pennsylvania,Allegheny,40.4396,-79.9763,1722206,2116,America/New_York,15216 15217 15214 15212 15210 15211 15218 15219 15290 15233 15260 15232 15205 15204 15207 15206 15201 15203 15208 15224 15213 15234 15222 15221 15220 15226 15120 15230 15231 15240 15242 15244 15250 15251 15252 15253 15254 15255 15257 15258 15259 15261 15262 15264 15265 15267 15268 15270 15272 15274 15275 15276 15277 15278 15279 15281 15282 15283 15286 15289 15295 33 | Sacramento,California,Sacramento,38.5666,-121.4683,1830061,1952,America/Los_Angeles,95821 95823 95838 95832 95833 95831 95834 95835 95811 95814 95815 95816 95818 95819 95828 95820 95822 95825 95824 95826 95817 94203 94204 94205 94207 94208 94209 94211 94229 94230 94232 94234 94235 94236 94237 94239 94240 94244 94245 94247 94248 94249 94250 94252 94254 94256 94257 94258 94259 94261 94262 94263 94267 94268 94269 94271 94273 94274 94277 94278 94279 94280 94282 94283 94284 94285 94286 94287 94288 94289 94290 94291 94293 94294 94295 94296 94297 94298 94299 95812 95813 95840 95851 95852 95853 95867 95894 34 | Riverside,California,Riverside,33.9382,-117.3949,2065627,1544,America/Los_Angeles,92508 92503 92501 92505 92504 92507 92506 92502 92513 92514 92516 92517 92521 92522 35 | San Francisco,California,San Francisco,37.7561,-122.4429,3548847,7170,America/Los_Angeles,94130 94131 94132 94133 94134 94108 94103 94102 94105 94104 94158 94124 94123 94122 94121 94129 94110 94118 94112 94116 94117 94114 94115 94111 94109 94107 94127 94119 94120 94125 94126 94137 94139 94140 94141 94142 94143 94144 94145 94146 94147 94151 94159 94160 94161 94163 94164 94172 94177 94188 36 | San Diego,California,San Diego,32.8312,-117.1225,3181172,1670,America/Los_Angeles,92109 92108 92106 92103 92111 92117 92154 92140 92107 92105 92104 92102 92071 92132 92130 92131 92134 92139 92025 92027 92147 92145 92014 92119 92110 92121 92120 92123 92122 92124 92127 92126 92129 92128 92101 92037 92173 92113 92114 92115 92116 92038 92039 92072 92092 92093 92112 92137 92138 92142 92143 92149 92150 92152 92153 92158 92159 92160 92161 92163 92165 92166 92167 92168 92169 92170 92171 92172 92174 92175 92176 92177 92179 92182 92186 92187 92190 92191 92192 92193 92195 92196 92197 92198 92199 37 | San Jose,California,Santa Clara,37.3020,-121.8488,1804359,2242,America/Los_Angeles,95118 95128 95124 95125 95126 95127 95120 95123 95008 95002 95117 95116 95111 95110 95113 95112 95119 95121 95148 95133 95132 95131 95130 95136 95135 95134 95139 95138 95037 95013 95129 95122 95101 95103 95106 95109 95115 95141 95150 95151 95153 95154 95155 95156 95157 95158 95159 95160 95161 95164 95170 95172 95173 95190 95191 95192 95193 95194 95196 38 | Los Angeles,California,Los Angeles,34.1140,-118.4068,12740381,3275,America/Los_Angeles,90291 90293 90292 90029 91316 91311 90035 90008 90004 90005 90006 90007 90001 90002 90003 90710 90089 91306 91307 91344 91345 91340 91342 91343 90034 90037 90036 90031 90033 90039 90038 90247 90248 91411 91436 91371 91608 91605 91604 91607 91606 91601 91602 90402 90068 90062 90063 90061 90066 90067 90064 90065 91326 91324 91325 90013 90012 90011 90017 90016 90015 90014 90028 90090 90095 90094 91042 91040 90069 91352 91356 91402 90041 90042 90043 90044 90045 90046 90047 90048 90049 90019 90018 90010 91423 90210 91303 91304 90079 90071 90077 90059 91331 91330 91335 90026 90027 90024 90025 90023 90020 90021 90272 90732 90731 90230 91406 91405 91403 91401 91367 91364 90032 90057 90058 90744 90501 90502 90009 90030 90050 90051 90053 90054 90055 90070 90072 90074 90075 90076 90078 90080 90081 90082 90083 90084 90086 90087 90088 90093 90099 90189 90213 90294 90296 90733 90734 90748 91041 91043 91305 91308 91309 91313 91327 91328 91329 91333 91334 91337 91346 91353 91357 91365 91392 91393 91394 91395 91396 91404 91407 91408 91409 91410 91412 91413 91416 91426 91470 91482 91495 91496 91499 91603 91609 91610 91611 91612 91614 91615 91616 91617 91618 39 | Las Vegas,Nevada,Clark,36.2288,-115.2603,2044731,1829,America/Los_Angeles,89149 89107 89106 89104 89102 89101 89108 89138 89130 89131 89134 89143 89146 89145 89144 89124 89110 89117 89129 89128 88901 88905 89114 89116 89125 89127 89133 89137 89151 89152 89153 89155 89158 89163 89164 89180 89185 89195 40 | Denver,Colorado,Denver,39.7621,-104.8759,2741534,1745,America/Denver,80264 80218 80230 80231 80236 80237 80235 80238 80239 80123 80249 80247 80246 80290 80293 80294 80219 80210 80211 80212 80216 80221 80220 80223 80222 80224 80227 80209 80207 80206 80205 80204 80202 80014 80203 80201 80208 80217 80225 80243 80244 80248 80250 80251 80252 80256 80257 80259 80261 80262 80263 80265 80266 80271 80273 80274 80281 80291 80299 41 | Chicago,Illinois,Cook,41.8373,-87.6861,8639278,4585,America/Chicago,60018 60649 60641 60640 60643 60642 60645 60644 60647 60646 60616 60617 60614 60615 60612 60613 60610 60611 60618 60619 60631 60827 60638 60639 60634 60636 60637 60630 60632 60633 60605 60604 60607 60606 60601 60603 60602 60609 60608 60106 60661 60660 60659 60652 60653 60656 60657 60654 60655 60651 60623 60622 60621 60620 60626 60625 60624 60629 60628 60707 60664 60666 60668 60669 60670 60673 60674 60675 60677 60678 60680 60681 60684 60685 60686 60687 60688 60689 60690 60691 60693 60694 60695 60696 60697 60699 60701 42 | Atlanta,Georgia,Fulton,33.7627,-84.4231,5080712,1370,America/New_York,30334 30331 30332 30309 30308 30307 30303 30354 30327 30326 30324 30319 30316 30342 30305 30306 30317 30314 30315 30312 30313 30310 30311 30363 30318 30301 30302 30304 30321 30325 30343 30348 30353 30355 30357 30358 30361 30362 30368 30369 30370 30371 30375 30377 30378 30380 30385 30388 30392 30394 30396 30398 31106 31107 31119 31126 31131 31139 31141 31145 31146 31150 31156 31192 31193 31195 31196 39901 43 | Indianapolis,Indiana,Marion,39.7771,-86.1458,1550488,913,America/Indiana/Indianapolis,46237 46218 46219 46217 46214 46260 46268 46226 46224 46229 46228 46183 46231 46234 46235 46236 46239 46254 46208 46201 46203 46202 46205 46204 46256 46250 46259 46227 46225 46222 46221 46220 46113 46278 46241 46240 46206 46207 46209 46210 46211 46230 46242 46244 46247 46249 46251 46253 46255 46262 46274 46275 46277 46282 46283 46285 46291 46296 46298 44 | Oklahoma City,Oklahoma,Oklahoma,35.4677,-97.5138,948154,406,America/Chicago,73012 73099 73097 73119 73118 73114 73117 73116 73111 73112 73020 73173 73013 73142 73141 73145 73149 73078 73106 73107 74857 73139 73132 73131 73135 73134 73008 73084 73105 73102 73162 73054 73151 73150 73159 73064 73108 73109 73104 73103 73129 73179 73170 73049 73169 73165 73127 73120 73121 73122 73128 73101 73113 73123 73124 73125 73126 73136 73137 73140 73143 73144 73146 73147 73148 73152 73153 73154 73155 73156 73157 73163 73164 73167 73172 73178 73184 73189 73190 73194 73195 73196 45 | Phoenix,Arizona,Maricopa,33.5722,-112.0891,4054083,1204,America/Phoenix,85008 85009 85003 85006 85007 85004 85083 85086 85087 85085 85383 85304 85306 85308 85020 85021 85022 85023 85024 85027 85028 85029 85353 85013 85015 85014 85254 85044 85045 85042 85043 85040 85041 85048 85054 85037 85035 85034 85033 85032 85031 85019 85018 85012 85017 85016 85307 85310 85051 85050 85053 85001 85002 85005 85010 85011 85025 85026 85030 85036 85038 85046 85060 85061 85062 85063 85064 85065 85066 85067 85068 85069 85070 85071 85072 85073 85074 85075 85076 85078 85079 85080 85082 85098 46 | Tucson,Arizona,Pima,32.1558,-110.8777,860333,887,America/Phoenix,85705 85707 85706 85756 85723 85726 85724 85701 85708 85748 85745 85747 85716 85714 85715 85712 85713 85710 85711 85719 85730 85702 85703 85709 85717 85720 85721 85722 85725 85731 85732 85738 85751 85754 85775 47 | Bridgeport,Connecticut,Fairfield,41.1909,-73.1958,934289,3508,America/New_York,06605 06604 06607 06606 06608 06610 06601 06602 06673 06699 48 | Hartford,Connecticut,Hartford,41.7661,-72.6834,913587,2737,America/New_York,06106 06105 06103 06120 06112 06160 06114 06101 06102 06104 06115 06123 06126 06132 06134 06140 06141 06142 06143 06144 06145 06146 06147 06150 06151 06152 06153 06154 06155 06156 06161 06167 06176 06180 06183 06199 49 | Baltimore,Maryland,Baltimore (city),39.3051,-76.6144,2181206,2931,America/New_York,21218 21211 21210 21213 21212 21215 21214 21217 21216 21231 21230 21239 21251 21209 21202 21206 21207 21205 21226 21201 21223 21224 21225 21229 21203 21233 21235 21241 21263 21264 21270 21273 21275 21278 21279 21280 21281 21282 21284 21285 21287 21288 21289 21290 21297 21298 50 | Boston,Massachusetts,Suffolk,42.3189,-71.0838,4556916,5373,America/New_York,02120 02121 02122 02124 02125 02126 02127 02128 02129 02210 02215 02467 02119 02118 02111 02110 02113 02115 02114 02116 02199 02134 02136 02135 02132 02131 02130 02203 02163 02152 02108 02109 02112 02117 02123 02133 02137 02196 02201 02204 02205 02206 02211 02212 02217 02222 02241 02266 02283 02284 02293 02297 02298 51 | Cleveland,Ohio,Cuyahoga,41.4766,-81.6805,1731637,1917,America/New_York,44135 44128 44120 44119 44113 44112 44111 44110 44115 44114 44144 44127 44104 44105 44106 44101 44102 44103 44108 44109 44181 44188 44190 44191 44192 44193 44194 44195 44197 44198 44199 52 | Columbus,Ohio,Franklin,39.9859,-82.9852,1495146,1522,America/New_York,43026 43109 43054 43220 43221 43222 43223 43224 43081 43228 43227 43210 43213 43212 43215 43214 43217 43219 43002 43004 43068 43085 43240 43229 43235 43232 43231 43230 43119 43110 43017 43016 43137 43211 43202 43203 43201 43206 43207 43204 43205 43209 43216 43218 43226 43234 43236 43251 43260 43266 43268 43270 43271 43272 43279 43287 43291 53 | Cincinnati,Ohio,Hamilton,39.1412,-84.5060,1634573,1480,America/New_York,45219 45213 45212 45211 45217 45216 45214 45225 45229 45226 45227 45224 45204 45205 45206 45207 45202 45203 45208 45209 45223 45239 45238 45237 45220 45230 45233 45232 45201 45221 45222 45234 45235 45250 45253 45254 45258 45262 45263 45264 45267 45268 45269 45270 45271 45273 45274 45275 45277 45296 45298 45299 45999 54 | Salt Lake City,Utah,Salt Lake,40.7774,-111.9301,1061156,672,America/Denver,84116 84115 84113 84112 84111 84144 84128 84180 84108 84101 84102 84103 84104 84105 84106 84110 84114 84122 84132 84133 84134 84136 84138 84139 84143 84145 84147 84148 84150 84151 84152 84158 84189 84190 84199 55 | Saint Louis,Missouri,St. Louis (city),38.6358,-90.2451,2096990,1940,America/Chicago,63110 63111 63112 63113 63115 63116 63118 63120 63107 63106 63104 63103 63102 63101 63109 63108 63155 63139 63137 63143 63147 63145 63150 63151 63156 63157 63158 63160 63163 63164 63166 63167 63169 63171 63177 63178 63179 63180 63182 63188 63195 63197 63199 56 | Kansas City,Missouri,Jackson,39.1239,-94.5541,1590762,590,America/Chicago,64163 64164 64165 64167 64161 64053 64119 64118 64151 64153 64155 64154 64157 64156 64158 64108 64109 64102 64105 64101 64128 64124 64125 64126 64127 64120 64123 64129 64166 64192 64114 64117 64116 64111 64110 64113 64112 64132 64130 64146 64145 64149 64147 64106 64139 64138 64133 64131 64137 64136 64134 64121 64141 64144 64148 64162 64168 64170 64171 64179 64180 64184 64187 64188 64190 64191 64195 64196 64197 64198 64199 64999 57 | Minneapolis,Minnesota,Hennepin,44.9635,-93.2679,2866604,2957,America/Chicago,55402 55409 55408 55407 55406 55405 55404 55403 55401 55417 55455 55430 55454 55418 55419 55410 55411 55412 55413 55414 55415 55416 55440 55458 55459 55460 55467 55470 55472 55473 55474 55478 55479 55480 55483 55484 55485 55486 55487 55488 58 | Detroit,Michigan,Wayne,42.3834,-83.1024,3520589,1872,America/Detroit,48209 48208 48201 48207 48206 48205 48204 48203 48238 48239 48234 48235 48233 48202 48243 48214 48215 48216 48217 48210 48211 48212 48213 48219 48228 48224 48227 48226 48221 48223 48222 48231 48232 48244 48255 48260 48264 48265 48266 48267 48268 48269 48272 48275 48277 48278 48279 48288 59 | Providence,Rhode Island,Providence,41.8229,-71.4186,1198789,3760,America/New_York,02903 02906 02907 02904 02905 02908 02909 02912 02901 02902 02918 02940 60 | Louisville,Kentucky,Jefferson,38.1662,-85.6488,1003412,902,America/New_York,40177 40245 40241 40218 40219 40214 40216 40211 40213 40059 40291 40299 40220 40223 40222 40229 40228 40023 40272 40207 40209 40258 40118 40018 40027 61 | Portland,Oregon,Multnomah,45.5372,-122.6500,2027629,1851,America/Los_Angeles,97227 97221 97220 97229 97203 97202 97201 97206 97205 97204 97209 97208 97266 97219 97212 97236 97232 97233 97230 97239 97218 97214 97215 97216 97217 97210 97211 97213 97207 97228 97238 97240 97242 97250 97251 97252 97253 97254 97256 97258 97280 97282 97283 97286 97290 97291 97292 97293 97294 97296 62 | -------------------------------------------------------------------------------- /src/cityreader/cityreader.py: -------------------------------------------------------------------------------- 1 | # Create a class to hold a city location. Call the class "City". It should have 2 | # fields for name, lat and lon (representing latitude and longitude). 3 | 4 | 5 | # We have a collection of US cities with population over 750,000 stored in the 6 | # file "cities.csv". (CSV stands for "comma-separated values".) 7 | # 8 | # In the body of the `cityreader` function, use Python's built-in "csv" module 9 | # to read this file so that each record is imported into a City instance. Then 10 | # return the list with all the City instances from the function. 11 | # Google "python 3 csv" for references and use your Google-fu for other examples. 12 | # 13 | # Store the instances in the "cities" list, below. 14 | # 15 | # Note that the first line of the CSV is header that describes the fields--this 16 | # should not be loaded into a City object. 17 | cities = [] 18 | 19 | def cityreader(cities=[]): 20 | # TODO Implement the functionality to read from the 'cities.csv' file 21 | # Ensure that the lat and lon valuse are all floats 22 | # For each city record, create a new City instance and add it to the 23 | # `cities` list 24 | 25 | return cities 26 | 27 | cityreader(cities) 28 | 29 | # Print the list of cities (name, lat, lon), 1 record per line. 30 | for c in cities: 31 | print(c) 32 | 33 | # STRETCH GOAL! 34 | # 35 | # Allow the user to input two points, each specified by latitude and longitude. 36 | # These points form the corners of a lat/lon square. Pass these latitude and 37 | # longitude values as parameters to the `cityreader_stretch` function, along 38 | # with the `cities` list that holds all the City instances from the `cityreader` 39 | # function. This function should output all the cities that fall within the 40 | # coordinate square. 41 | # 42 | # Be aware that the user could specify either a lower-left/upper-right pair of 43 | # coordinates, or an upper-left/lower-right pair of coordinates. Hint: normalize 44 | # the input data so that it's always one or the other, then search for cities. 45 | # In the example below, inputting 32, -120 first and then 45, -100 should not 46 | # change the results of what the `cityreader_stretch` function returns. 47 | # 48 | # Example I/O: 49 | # 50 | # Enter lat1,lon1: 45,-100 51 | # Enter lat2,lon2: 32,-120 52 | # Albuquerque: (35.1055,-106.6476) 53 | # Riverside: (33.9382,-117.3949) 54 | # San Diego: (32.8312,-117.1225) 55 | # Los Angeles: (34.114,-118.4068) 56 | # Las Vegas: (36.2288,-115.2603) 57 | # Denver: (39.7621,-104.8759) 58 | # Phoenix: (33.5722,-112.0891) 59 | # Tucson: (32.1558,-110.8777) 60 | # Salt Lake City: (40.7774,-111.9301) 61 | 62 | # TODO Get latitude and longitude values from the user 63 | 64 | def cityreader_stretch(lat1, lon1, lat2, lon2, cities=[]): 65 | # within will hold the cities that fall within the specified region 66 | within = [] 67 | 68 | # Go through each city and check to see if it falls within 69 | # the specified coordinates. 70 | 71 | return within 72 | -------------------------------------------------------------------------------- /src/cityreader/test_cityreader.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from cityreader import City, cityreader 3 | 4 | def check_city(inp, exp): 5 | if inp.name != exp.name: 6 | return False 7 | if inp.lat != exp.lat: 8 | return False 9 | if inp.lon != exp.lon: 10 | return False 11 | return True 12 | 13 | class CityreaderTests(unittest.TestCase): 14 | def setUp(self): 15 | self.cities = cityreader() 16 | self.expected = [ 17 | City("Seattle", 47.6217,-122.3238), 18 | City("Richmond", 37.5294,-77.4755), 19 | City("Virginia Beach", 36.7335,-76.0435), 20 | City("Washington", 38.9047,-77.0163), 21 | City("Milwaukee", 43.064,-87.9669), 22 | City("Orlando", 28.4801,-81.3448), 23 | City("Miami", 25.784,-80.2102), 24 | City("Tampa", 27.9937,-82.4454), 25 | City("Jacksonville", 30.3322,-81.6749), 26 | City("Albuquerque", 35.1055,-106.6476), 27 | City("Fort Worth", 32.7813,-97.3466), 28 | City("McAllen", 26.2203,-98.2457), 29 | City("El Paso", 31.8478,-106.431), 30 | City("Dallas", 32.7938,-96.7659), 31 | City("Austin", 30.3038,-97.7545), 32 | City("Houston", 29.7871,-95.3936), 33 | City("San Antonio", 29.4722,-98.5247), 34 | City("New Orleans", 30.0687,-89.9288), 35 | City("Charlotte", 35.208,-80.8308), 36 | City("Raleigh", 35.8323,-78.6441), 37 | City("Omaha", 41.2634,-96.0453), 38 | City("Memphis", 35.1047,-89.9773), 39 | City("Nashville", 36.1714,-86.7844), 40 | City("Buffalo", 42.9016,-78.8487), 41 | City("Queens", 40.7498,-73.7976), 42 | City("New York", 40.6943,-73.9249), 43 | City("Bronx", 40.8501,-73.8662), 44 | City("Brooklyn", 40.6501,-73.9496), 45 | City("Manhattan", 40.7834,-73.9662), 46 | City("Philadelphia", 40.0076,-75.134), 47 | City("Pittsburgh", 40.4396,-79.9763), 48 | City("Sacramento", 38.5666,-121.4683), 49 | City("Riverside", 33.9382,-117.3949), 50 | City("San Francisco", 37.7561,-122.4429), 51 | City("San Diego", 32.8312,-117.1225), 52 | City("San Jose", 37.302,-121.8488), 53 | City("Los Angeles", 34.114,-118.4068), 54 | City("Las Vegas", 36.2288,-115.2603), 55 | City("Denver", 39.7621,-104.8759), 56 | City("Chicago", 41.8373,-87.6861), 57 | City("Atlanta", 33.7627,-84.4231), 58 | City("Indianapolis", 39.7771,-86.1458), 59 | City("Oklahoma City", 35.4677,-97.5138), 60 | City("Phoenix", 33.5722,-112.0891), 61 | City("Tucson", 32.1558,-110.8777), 62 | City("Bridgeport", 41.1909,-73.1958), 63 | City("Hartford", 41.7661,-72.6834), 64 | City("Baltimore", 39.3051,-76.6144), 65 | City("Boston", 42.3189,-71.0838), 66 | City("Cleveland", 41.4766,-81.6805), 67 | City("Columbus", 39.9859,-82.9852), 68 | City("Cincinnati", 39.1412,-84.506), 69 | City("Salt Lake City", 40.7774,-111.9301), 70 | City("Saint Louis", 38.6358,-90.2451), 71 | City("Kansas City", 39.1239,-94.5541), 72 | City("Minneapolis", 44.9635,-93.2679), 73 | City("Detroit", 42.3834,-83.1024), 74 | City("Providence", 41.8229,-71.4186), 75 | City("Louisville", 38.1662,-85.6488), 76 | City("Portland", 45.5372,-122.65) 77 | ] 78 | 79 | def test_cityreader_correctness(self): 80 | self.assertEqual(len(self.cities), 60) 81 | for i in range(len(self.cities)): 82 | self.assertTrue(check_city(self.cities[i], self.expected[i])) 83 | 84 | 85 | if __name__ == '__main__': 86 | unittest.main() -------------------------------------------------------------------------------- /src/cityreader/test_stretch.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from cityreader import City, cityreader, cityreader_stretch 3 | 4 | def check_city(inp, exp): 5 | if inp.name != exp.name: 6 | return False 7 | if inp.lat != exp.lat: 8 | return False 9 | if inp.lon != exp.lon: 10 | return False 11 | return True 12 | 13 | class CityreaderTests(unittest.TestCase): 14 | def setUp(self): 15 | self.cities = cityreader() 16 | 17 | def test_cityreader_stretch_correctness(self): 18 | expected = [ 19 | City("Albuquerque", 35.1055,-106.6476), 20 | City("Riverside", 33.9382,-117.3949), 21 | City("San Diego", 32.8312,-117.1225), 22 | City("Los Angeles", 34.114,-118.4068), 23 | City("Las Vegas", 36.2288,-115.2603), 24 | City("Denver", 39.7621,-104.8759), 25 | City("Phoenix", 33.5722,-112.0891), 26 | City("Tucson", 32.1558,-110.8777), 27 | City("Salt Lake City", 40.7774,-111.9301) 28 | ] 29 | 30 | inp = cityreader_stretch(45, -100, 32, -120, self.cities) 31 | 32 | self.assertEqual(len(inp), len(expected)) 33 | 34 | for i in range(len(inp)): 35 | self.assertTrue(check_city(inp[i], expected[i])) 36 | 37 | inp = cityreader_stretch(32, -120, 45, -100, self.cities) 38 | 39 | self.assertEqual(len(inp), len(expected)) 40 | 41 | for i in range(len(inp)): 42 | self.assertTrue(check_city(inp[i], expected[i])) 43 | 44 | expected = [ 45 | City("Richmond", 37.5294,-77.4755), 46 | City("Virginia Beach", 36.7335,-76.0435), 47 | City("Washington", 38.9047,-77.0163), 48 | City("Orlando", 28.4801,-81.3448), 49 | City("Miami", 25.784,-80.2102), 50 | City("Tampa", 27.9937,-82.4454), 51 | City("Jacksonville", 30.3322,-81.6749), 52 | City("Albuquerque", 35.1055,-106.6476), 53 | City("Fort Worth", 32.7813,-97.3466), 54 | City("McAllen", 26.2203,-98.2457), 55 | City("El Paso", 31.8478,-106.431), 56 | City("Dallas", 32.7938,-96.7659), 57 | City("Austin", 30.3038,-97.7545), 58 | City("Houston", 29.7871,-95.3936), 59 | City("San Antonio", 29.4722,-98.5247), 60 | City("New Orleans", 30.0687,-89.9288), 61 | City("Charlotte", 35.208,-80.8308), 62 | City("Raleigh", 35.8323,-78.6441), 63 | City("Memphis", 35.1047,-89.9773), 64 | City("Nashville", 36.1714,-86.7844), 65 | City("Riverside", 33.9382,-117.3949), 66 | City("San Diego", 32.8312,-117.1225), 67 | City("Los Angeles", 34.114,-118.4068), 68 | City("Las Vegas", 36.2288,-115.2603), 69 | City("Denver", 39.7621,-104.8759), 70 | City("Atlanta", 33.7627,-84.4231), 71 | City("Indianapolis", 39.7771,-86.1458), 72 | City("Oklahoma City", 35.4677,-97.5138), 73 | City("Phoenix", 33.5722,-112.0891), 74 | City("Tucson", 32.1558,-110.8777), 75 | City("Baltimore", 39.3051,-76.6144), 76 | City("Columbus", 39.9859,-82.9852), 77 | City("Cincinnati", 39.1412,-84.506), 78 | City("Saint Louis", 38.6358,-90.2451), 79 | City("Kansas City", 39.1239,-94.5541), 80 | City("Louisville", 38.1662,-85.6488) 81 | ] 82 | 83 | inp = cityreader_stretch(40, -50, 12, -120, self.cities) 84 | 85 | for i in range(len(inp)): 86 | self.assertTrue(check_city(inp[i], expected[i])) 87 | 88 | 89 | if __name__ == '__main__': 90 | unittest.main() -------------------------------------------------------------------------------- /src/comp/comp.py: -------------------------------------------------------------------------------- 1 | # The following list comprehension exercises will make use of the 2 | # defined Human class. 3 | class Human: 4 | def __init__(self, name, age): 5 | self.name = name 6 | self.age = age 7 | 8 | def __repr__(self): 9 | return f"" 10 | 11 | humans = [ 12 | Human("Alice", 29), 13 | Human("Bob", 32), 14 | Human("Charlie", 37), 15 | Human("Daphne", 30), 16 | Human("Eve", 26), 17 | Human("Frank", 18), 18 | Human("Glenn", 42), 19 | Human("Harrison", 12), 20 | Human("Igon", 41), 21 | Human("David", 31), 22 | ] 23 | 24 | # Write a list comprehension that creates a list of names of everyone 25 | # whose name starts with 'D': 26 | print("Starts with D:") 27 | a = [] 28 | print(a) 29 | 30 | # Write a list comprehension that creates a list of names of everyone 31 | # whose name ends in "e". 32 | print("Ends with e:") 33 | b = [] 34 | print(b) 35 | 36 | # Write a list comprehension that creates a list of names of everyone 37 | # whose name starts with any letter between 'C' and 'G' inclusive. 38 | print("Starts between C and G, inclusive:") 39 | c = [] 40 | print(c) 41 | 42 | # Write a list comprehension that creates a list of all the ages plus 10. 43 | print("Ages plus 10:") 44 | d = [] 45 | print(d) 46 | 47 | # Write a list comprehension that creates a list of strings which are the name 48 | # joined to the age with a hyphen, for example "David-31", for all humans. 49 | print("Name hyphen age:") 50 | e = [] 51 | print(e) 52 | 53 | # Write a list comprehension that creates a list of tuples containing name and 54 | # age, for example ("David", 31), for everyone between the ages of 27 and 32, 55 | # inclusive. 56 | print("Names and ages between 27 and 32:") 57 | f = [] 58 | print(f) 59 | 60 | # Write a list comprehension that creates a list of new Humans like the old 61 | # list, except with all the names uppercase and the ages with 5 added to them. 62 | # The "humans" list should be unmodified. 63 | print("All names uppercase:") 64 | g = [] 65 | print(g) 66 | 67 | # Write a list comprehension that contains the square root of all the ages. 68 | print("Square root of ages:") 69 | import math 70 | h = [] 71 | print(h) 72 | -------------------------------------------------------------------------------- /src/comp/test_comp.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from comp import * 3 | 4 | def compare_humans(inp, exp): 5 | if len(inp) != len(exp): 6 | return False 7 | for i in range(len(inp)): 8 | if inp[i].name != exp[i].name: 9 | return False 10 | if inp[i].age != exp[i].age: 11 | return False 12 | return True 13 | 14 | class CompTests(unittest.TestCase): 15 | def test_starts_with_D(self): 16 | self.assertEqual(a, ['Daphne', 'David']) 17 | 18 | def test_ends_with_e(self): 19 | self.assertEqual(b, ['Alice', 'Charlie', 'Daphne', 'Eve']) 20 | 21 | def test_between_C_and_G(self): 22 | self.assertEqual(c, ['Charlie', 'Daphne', 'Eve', 'Frank', 'Glenn', 'David']) 23 | 24 | def test_ages_plus_10(self): 25 | self.assertEqual(d, [39, 42, 47, 40, 36, 28, 52, 22, 51, 41]) 26 | 27 | def test_name_hyphen_age(self): 28 | self.assertEqual(e, ['Alice-29', 'Bob-32', 'Charlie-37', 'Daphne-30', 'Eve-26', 'Frank-18', 'Glenn-42', 'Harrison-12', 'Igon-41', 'David-31']) 29 | 30 | def test_names_ages_between_27_and_32(self): 31 | self.assertEqual(f, [('Alice', 29), ('Bob', 32), ('Daphne', 30), ('David', 31)]) 32 | 33 | def test_all_names_uppercase(self): 34 | expected = [Human("ALICE", 34), Human("BOB", 37), Human("CHARLIE", 42), Human("DAPHNE", 35), Human("EVE", 31), Human("FRANK", 23), Human("GLENN", 47), Human("HARRISON", 17), Human("IGON", 46), Human("DAVID", 36)] 35 | self.assertTrue(compare_humans(g, expected)) 36 | 37 | def test_square_root_of_ages(self): 38 | self.assertEqual(h, [5.385164807134504, 5.656854249492381, 6.082762530298219, 5.477225575051661, 5.0990195135927845, 4.242640687119285, 6.48074069840786, 3.4641016151377544, 6.4031242374328485, 5.5677643628300215]) 39 | 40 | 41 | if __name__ == '__main__': 42 | unittest.main() 43 | -------------------------------------------------------------------------------- /src/oop/oop1.py: -------------------------------------------------------------------------------- 1 | # Write classes for the following class hierarchy: 2 | # 3 | # [Vehicle]->[FlightVehicle]->[Starship] 4 | # | | 5 | # v v 6 | # [GroundVehicle] [Airplane] 7 | # | | 8 | # v v 9 | # [Car] [Motorcycle] 10 | # 11 | # Each class can simply "pass" for its body. The exercise is about setting up 12 | # the hierarchy. 13 | # 14 | # e.g. 15 | # 16 | # class Whatever: 17 | # pass 18 | # 19 | # Put a comment noting which class is the base class 20 | -------------------------------------------------------------------------------- /src/oop/oop2.py: -------------------------------------------------------------------------------- 1 | # To the GroundVehicle class, add method drive() that returns "vroooom". 2 | # 3 | # Also change it so the num_wheels defaults to 4 if not specified when the 4 | # object is constructed. 5 | 6 | class GroundVehicle(): 7 | def __init__(self, num_wheels): 8 | self.num_wheels = num_wheels 9 | 10 | # TODO 11 | 12 | 13 | # Subclass Motorcycle from GroundVehicle. 14 | # 15 | # Make it so when you instantiate a Motorcycle, it automatically sets the number 16 | # of wheels to 2 by passing that to the constructor of its superclass. 17 | # 18 | # Override the drive() method in Motorcycle so that it returns "BRAAAP!!" 19 | 20 | # TODO 21 | 22 | vehicles = [ 23 | GroundVehicle(), 24 | GroundVehicle(), 25 | Motorcycle(), 26 | GroundVehicle(), 27 | Motorcycle(), 28 | ] 29 | 30 | # Go through the vehicles list and print the result of calling drive() on each. 31 | 32 | # TODO 33 | -------------------------------------------------------------------------------- /src/oop/test_oop1.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from oop1 import * 3 | 4 | class Oop1Tests(unittest.TestCase): 5 | def setUp(self): 6 | self.vehicle = Vehicle() 7 | self.flight_vehicle = FlightVehicle() 8 | self.ground_vehicle = GroundVehicle() 9 | self.car = Car() 10 | self.motorcycle = Motorcycle() 11 | self.starship = Starship() 12 | self.airplane = Airplane() 13 | 14 | def test_flight_vehicle(self): 15 | self.assertTrue(isinstance(self.flight_vehicle, FlightVehicle)) 16 | self.assertTrue(isinstance(self.flight_vehicle, Vehicle)) 17 | 18 | def test_ground_vehicle(self): 19 | self.assertTrue(isinstance(self.ground_vehicle, GroundVehicle)) 20 | self.assertTrue(isinstance(self.ground_vehicle, Vehicle)) 21 | 22 | def test_starship(self): 23 | self.assertTrue(isinstance(self.starship, Starship)) 24 | self.assertTrue(isinstance(self.starship, FlightVehicle)) 25 | self.assertTrue(isinstance(self.starship, Vehicle)) 26 | 27 | def test_airplane(self): 28 | self.assertTrue(isinstance(self.airplane, Airplane)) 29 | self.assertTrue(isinstance(self.airplane, FlightVehicle)) 30 | self.assertTrue(isinstance(self.starship, Vehicle)) 31 | 32 | def test_car(self): 33 | self.assertTrue(isinstance(self.car, Car)) 34 | self.assertTrue(isinstance(self.car, GroundVehicle)) 35 | self.assertTrue(isinstance(self.car, Vehicle)) 36 | 37 | def test_motocycle(self): 38 | self.assertTrue(isinstance(self.motorcycle, Motorcycle)) 39 | self.assertTrue(isinstance(self.motorcycle, GroundVehicle)) 40 | self.assertTrue(isinstance(self.motorcycle, Vehicle)) 41 | 42 | 43 | if __name__ == '__main__': 44 | unittest.main() -------------------------------------------------------------------------------- /src/oop/test_oop2.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from oop2 import * 3 | 4 | class Oop2Tests(unittest.TestCase): 5 | def setUp(self): 6 | self.ground_vehicle = GroundVehicle() 7 | self.motorcycle = Motorcycle() 8 | 9 | def test_motorcycle_inheritance(self): 10 | self.assertTrue(isinstance(self.motorcycle, GroundVehicle)) 11 | 12 | def test_ground_vehicle_num_wheels(self): 13 | self.assertEqual(self.ground_vehicle.num_wheels, 4) 14 | 15 | def test_motocycle_num_wheels(self): 16 | self.assertEqual(self.motorcycle.num_wheels, 2) 17 | 18 | def test_ground_vehicle_drive(self): 19 | self.assertEqual(self.ground_vehicle.drive(), "vroooom") 20 | 21 | def test_motorcyle_drive(self): 22 | self.assertEqual(self.motorcycle.drive(), "BRAAAP!!") 23 | 24 | 25 | if __name__ == '__main__': 26 | unittest.main() --------------------------------------------------------------------------------