Changes between Version 86 and Version 87 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 10:58:48 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v86 v87 16 16 Python, like every programming language, has a structure. Here are the big parts: 17 17 18 * ''Variables'': Things you assign to and read from. Like in Algebra. `a="Dump Truck"` sets the 19 * ''Control Structures'': These are instructions like IF this is true THEN do that…. These are likegrammar rules, like use active voice, or use punctuation.18 * ''Variables'': Things you assign to and read from. Like in Algebra. `a="Dump Truck"` sets the variable A to the string "Dump Truck". You can set them to numbers to or fancy things like lists. They're basically the nouns. 19 * ''Control Structures'': These are instructions like IF this is true THEN do that…. These are like grammar rules, like use active voice, or use punctuation. 20 20 * ''Functions'': These do things. They take nouns as arguments, do something, and can return nouns. In `redCar = paintCarRed(blueCar)`, `paintCarRed` is a function. They're the verbs, they do things, and they take variables and return variables. Some functions are built in to Python, but you can create your own. 21 * '' Libraries'': A lot of other people have written functions to do things. A lot of things. When these things are bundled together they're called libraries. You can tell a computer to use a library and save your self a lotof typing.21 * ''Packages'': A lot of other people have written functions to do things. A lot of things. When these things are bundled together they're called ''packages''. You can tell a computer to use a library and save your self a lot of typing. 22 22 23 23 Much like in English, you blend all of these together to create stories, or ''programs''. Both have a beginning middle and end. So lets write the first program that all programmers start with: "Hello World" … … 289 289 Now that you seen the basics of the Python language, and have created your own functions. Its time to see what else is out there. It turns out there are A LOT of packages out there that contain custom functions for Python that do pretty much anything you'd want, from advanced machine intelligence, to 3D graphics, to yes, controlling robots. These packages were created by others and are offered for free, and others may be offered at a cost. 290 290 291 You can find these libraries by googling for with the term "<subject> python library". For example "spell check python library". This turns up [https://pythonhosted.org/pyenchant/ | PyEnchant] which describes how to use and access the library. There are probably others. You can also go to the [[https://pypi.python.org/pypi|Python Package Index]]. What ever you do, make sure you use the correct version of the library for the version of Python you're using (in our case, Python 3)291 You can find these packages by googling for with the term "<subject> python library". For example "spell check python library". This turns up [https://pythonhosted.org/pyenchant/ | PyEnchant] which describes how to use and access the library. There are probably others. You can also go to the [[https://pypi.python.org/pypi|Python Package Index]]. What ever you do, make sure you use the correct version of the library for the version of Python you're using (in our case, Python 3) 292 292 293 293 To use it in code, you use the !`import` keyword in Python like so: … … 302 302 It would be a enormous effort to create your own spell check library, so reusing one saves a lot of time. We'll be using this when we program robots because a lot of the work we need to do to communicate with the parts of a robot has already been done. And we want to spend time making robots do things, not figuring out how to communicate with then. 303 303 304 Unfortunately, you can't include external libraries in your code in our web-based code runner and run them, so you'll have to use your imagination to see how this particular example works. You'll use them a lot in the intermediate training as the year goes on.304 Unfortunately, you can't include external packages in your code in our web-based code runner and run them, so you'll have to use your imagination to see how this particular example works. You'll use them a lot in the intermediate training as the year goes on. This 305 305 306 306 = Final Exam = 307 307 [[Image(1B6AA343-B7D4-49F7-88DA-2AB89A7A4E72-5482-00000452F115F905_tmp.png,left,10%,margin=5)]] 308 309 ''' * '''Create a program that prints random fortune cookie sayings.''' 308 * ''Create a program that prints random fortune cookie sayings.''' 310 309 * Randomly build the sayingss from at least three different lists of nouns and verb phrases. Make the random sayings sound suitably cryptic and wise. 311 310 * The program should prompt the user for the number of sayings they want output, validate that it is indeed a number, and print out that many. … … 313 312 * If you need help, refer to this lesson, the [[https://docs.python.org/3/index.html | Official Python 3 Documentation]], and don't hesitate to ask the mentors. 314 313 315 '''= What's Next = 316 Well that concludes the Software Introduction. We welcome your feedback. Software takes a lot of work and study to write well, and this is just a taste. For those of you who select the Software team, we'll begin intermediate training with the Raspberry Pi, and show you how to write programs that use external libraries to communcation with the outside world through motors, sensors and the like. 314 = What's Next = Well that concludes the Software Introduction. We welcome your feedback. Software takes a lot of work and study to write well, and this is just a taste. For those of you who select the Software team, we'll begin intermediate training with the Raspberry Pi, and show you how to write programs that use external libraries to communcation with the outside world through motors, sensors and the like.''' 317 315 318 316 ----