Changes

Jump to navigation Jump to search

Workshop: Introduction to programming (with Python)

687 bytes added, 19:00, 7 November 2019
update workshop checklist to conform to standard pedagogy.
{{Workshop header}}
 
===Python===
Some Beginner Questions:
 
*What do you know about Python?
*Do you have any previous experience with Python or other programming languages?
 
 
Python Basics:
 
*Python is a flexible, high-level, procedural scripting language.
*It offers support for object-oriented programming and integrating libraries.
*It's super widely adopted!
 
<br />
==Welcome to Introduction to Programming!==
#'''Open a text editor''' - This is where we will be writing all of our code. There are many different editors you can use, so feel free to choose the one you are most comfortable with. The only requirement is that the text editor should be able to product plain text files. Windows users already have Notepad installed. Mac users have TextEdit (other text editors include TextWrangler, Atom, and much more).
#'''Write your code''' - To make this program as simple straightforward as possible we will simply write a print statement. After writing your print statement save the file to your Desktop (or whatever other directory you want) as "hello'''.py'''". All python files need to have the extension .py#[[File:Hello World Executed.png|thumb|Execute the code!]]'''Execute the code''' - Now is the fun part, running the code! Open up the command prompt (Terminal for Mac Users, Powershell for Windows). Navigate to the directory where you saved the file (ex: cd Desktop). Now execute your python code by typing "python [filename]" [[File:Hello World Executed.png|thumb|Execute the code!]]<br />
#Floats - Numbers w/ a decimal (ex: 1.0, 3.14, 7.77)
#Boolean - True or False
#Lists - An A sequential list of other variables (floats, integers, strings, more lists, or a mix) (ex: ['cat', 'dog', 999, 3.14, variable1])
===='''Defining Variables'''====
Answer: 1.5 + 3 = 4.5 but 4.5 is a float value. So for code #1 the answer is 4.5, but the "sum" variable in code #2 is an integer so the answer will be rounded down to 4.
It because of cases like these that sometimes we implement a technique known as casting. Casting simply means changing converting the type of information a variable holds. With casting we can turn a an int to a float, float to an int, str to an int, etc. We cast by writing the variable type we want ("float", "int", "str", etc.) followed by the variable/value we want to cast enclosed by parenthesis.
Examples:
*myList'''.insert('''x''')''' - Adds an element at the specified position (x)
*myList'''.clear()''' - Removes all the elements from the list
 
(We will discuss what methods are in a later section.)
<br />
*String - capitalize(), lower(), upper(), find()
*Int/Float - abs(), long(), pow(), round()
*List - append(), count(), pop(), sort(), reverse()
##To iterate a certain number of times - Use Python's range function to repeat the code block a certain number of times. The syntax for range is: range (start, stop[, step]). Just like in the other type of for loop, you can reference each element of the range function but naming it. The syntax for this for loop goes: '''for ('''element '''in range('''start, stop[, step]''')):''' '''''*code to repeat*''''' <br />
#'''Nested Loops''' - Loops can be nested inside of each other! For each iteration of the outer loop, the entire contents of the loop will be ran to completion (including other nested loops).
#'''Breaks and Continues''' - "Break" and "continue" are statements which can be placed inside of a loop to modify the loop for special cases. Break is used to break out of (or exit) a loop. Continue is used to stop the current iteration of the loop and start again from the beginning.   [[File:Break Flowchart.jpg|frameless]][[File:Continue Flow Chart.jpg|frameless]]
<br />
<br />
==Workshop checklist==
===Learning Objectives===
By the end of this Workshop, you should:
 
#be able to explain the purpose of programming languages.
#understand the difference between a script and the interactive shell.
#know the basic functionality of programming languages: sequencing, selecting, and iterating.
#have a basic understanding of computational thinking.
==Skills Checklist=Measurable Outcomes===By the end of this Workshop, you should be able to:
*#run Python Installationscripts on your system*How to write, save and run #use the interactive shell on your system.py files*How to enter Interactive Python*Basic Understanding #utilize the basic parts of Variables (how to definea program: variables, different types, casting)*Basic Understanding of Methods*Basic Understanding of If Statements (orobjects, and, else, elif)functions.*Basic Understanding of Loops (for loop, while loop, nested loop, break #code and continue)*Make test a program which accomplishes a Magic Conch Shell Demo!small task.

Navigation menu