Changes

Jump to navigation Jump to search

Workshop: Introduction to programming (with Python)

2,711 bytes added, 21:56, 9 September 2019
other resources
==Welcome to Introduction to Programming!!==
'''The first step''' is to download Python-===Setting up your work station===
If you haven’t yet got python, the latest official installation packages #'''Download Python -''' You can be found download it here:http#'''Check that your installation was successful -''' We will do this by checking the version of python we just downloaded. We can do this by opening up our command prompt and simply typing "python --version". If you did everything right you should see a message that looks something like this://python"Python 3.7.org/download/3"#'''Let's test our distribution''' - Let's get our first introduction into Python 3 is preferable, being the newest version out!programming by making a hello world file.
'''The second step''' is to understand the different things we can do with it!<br />
Ok, so python ==Basic Hello World Program==A hello world program is this thing called a programming language. It takes text the most basic program you can write to test that you’ve written (usually referred to as code), turns it into instructions for your computer, and runs those instructionsdistribution is working smoothly. We’ll be learning how to write code to do cool and useful stuff[[File:Hello world example. No longer png|thumb|The print statement will you be bound simply print out "Hello world!" to use others’ programs to do things with your computer - you can make your own!the console when ran.]]
We #'''Open a text editor''' - This is where we will be writing all of our code. There are many different editors you can use Python , 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 as possible we will simply write a calculatorprint 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#'''Execute the code''' - Now is the fun part, very advanced calculatorrunning the code! Open up the command prompt (Terminal for Mac Users, build softwares, games, and analyze dataPowershell 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 />
We will start with the most simple concept- variable!
We name a variable and stick to it a number==Variables==Now that we understand the basic workflow of python (create code in text editor → execute in command prompt), a word, a list etc. This way we can call it in start discussing the futuredifferent functions and capabilities of Python. We can start this discussion with variables.example You can think of variables as the objects that store information for a our program. A variable is a=6has two basic parts; '''A name''' (which we will use to refer to the variable) and '''A value''' (the info we care about). Besides those two parts, variables can hold different types of information.
If we want to print the variable we can do - print(a)
and we will get 6.
In addition we can use python as a calculator-just type 6+6 and run it and you will get 12.'''Types Of Variables:'''
#Strings - A sequence of characters (ex: "Python is fun!")
#Integers - Whole numbers (ex: 3, 10, 999)
#Floats - Numbers w/ a decimal (ex: 1.0, 3.14, 7.77)
#Lists - An sequential list of other variables (floats, integers, strings, more lists, or a mix) (ex: ['cat', 'dog', 999, 3.14, variable1])
Types of inputs are integers, floats, string, and list (those are the basic ones that we will use)-
integer is a whole number-> int(), 6, 7'''Defining Variables:'''
float One of the great features of Python is not that the built in compiler can intelligently figure out what type of variable your specified variables should be and takes care of this distinction '''automatically'''. This means defining variables is easier in Python than some other languages you may be familiar with. We define a whole number-> 6variable by writing its name, followed by an equal sign, followed by the value of the variable (ex: pi=3.2514, name="Dylan", 7eq="3+4"). We can also define variables without setting the values immediately.3333To do this we need to tell the compiler what type of variable we need (since it can't figure it out automatically) (ex: int pi, str myName)
string is a word or a phrase- the written part of something-> 'My name is', '6', (we use the tags to help Python recognize it).
list Important Note: The standard naming convention of variables follows: The first word is a list of integers, floats or strings-> [1,2,3,4always all lowercase then the proceeding words begin with an uppercase letter (ex: myVariable,5], ['1reallyAwesomeInteger). You don't need to follow this convention,'2','3','4','5']but it is worth knowing.
Now that we are a bit more familiar lets see how we can use Python to solve Problems!!!'''Updating Variables:'''
We will go To update a variable (change it's value later on in the code) we simply need to project Euler- https://projecteulerredefine it's value.net or httpYou can do this by://rosalind.info/problems/locations/
The first one is more of solving math problems with Python (or any other software) and the latter is solving real life Bioinformatics problems!!variableName = [new value]
lets do together the first problem of Project Euler!'''Casting Variables:'''
When we get into more complex implementations our variable type will become very important. Ask yourself 'what is the difference between these two codes?'
Another great source you can use #float sum = 1.5 + 3#int sum = 1.5 + 3 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 order code #2 is an integer so the answer will be rounded down to learn 4. It because of cases like these that sometimes we implement a technique known as casting. Casting simply means changing the basics type of information a variable holds. With casting we can turn a 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: *float(3) → 3.0*int(2.9999) → 2*int("1964") → 1964 == Other Educational Resources for Python == * The official Python isDocumentation - https://docs.python.org/3/* Tutorials -https://thepythonguru.com* Challenging Math/Computational Problems - https://projecteuler. This website provides pictures and explanations on the different structures we have in Python. You can also find there some more advanced programing tutorials.net
118
edits

Navigation menu