Download presentation
Presentation is loading. Please wait.
Published byMaud Hopkins Modified over 9 years ago
1
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
2
- 2 - Objectives Download, Installation and Setup Write Your First Program More Maths Different Types of Numbers Questions & Answers
3
- 3 - Setup When the USB is passed to you plug it in and COPY the Folder on your desktop Wait for my instruction! Seriously if you don’t wait you’ll mess up your computer (in the worst way possible), I’ll go through is slowly and ask me any questions if anything looks different for you then when I’m doing it!
4
- 4 - CMD / Terminal A Command Prompt / Terminal is an entry point for typing computer commands in the Command Prompt / Terminal window. By typing commands at the Command Prompt / Terminal, you can perform tasks on your computer without using the Windows / Mac graphical interface. Python can run within the CMD / Terminal, but for CMD / Terminal to see Python we have to configure the path variables on your computer.
5
- 5 - Path Config For Windows Right click your computer and go to Properties
6
- 6 - Path Config For Windows Press Advanced System Settings
7
- 7 - Path Config For Windows Press Environment Variables
8
- 8 - Path Config For Windows Look at the box that says User Variables at the top. Press EDIT now add a ; to the end of the current path and add C:/Python after the ; if you don’t have a path already there just paste C:/Python in it and press ok. Restart Your Command prompt and type python in it, if you see >>> That means you have successfully installed python
9
- 9 - Path Config For Mac Bust out your terminal, and type python in it. If an error happened... Good. Next type vim /etc/paths Than type the path to your python directory with the python.exe in it, to your /etc/paths Restart your terminal and type python in it.
10
- 10 - Write Your First Program Bust open your cmd / terminal and type python in it. You Should see something similar to
11
- 11 - Write Your First Program Type in print(“Hello World”) You are now part of the 6% of the population that has ever written a program of any type!
12
- 12 - What Did You Just Do? The command that you have just written was called print(). Print is a function in python that allows you to display text to the console. CMD / Terminal acts like a console. A console is a text output device for system processes. Basically it allows getting inputs from the user and display outputs easily from python.
13
- 13 - Ok. But What Else Can I Do You can also do arithmetic in python. –You can add / subtract numbers, try typing these in 2 + 2 3 – 10 2 + 3 – 10 –As you can see you can add and subtract multiple numbers together and the console will display its interpreted output
14
- 14 - More Maths As you can tell you can also multiply and divide. To multiply two numbers together use the * sign. To divide two numbers use the / sign. Test these out. –2 * 2 –3 / 3 –5 * 2 / 2
15
- 15 - Adding and Multiplying As you can probably tell you can add subtract multiply and divide all in the same line. Try these examples and try to guess what the output will be. –2 * 2 + 2 –8 / 4 * 2 – 8 –3 + 3 * 3 If you guessed 18 for the last one you might have been surprised to find out that the output was 12. This is because python follows PEMDAS.
16
- 16 - Orders of Operations P: Parentheses E: Exponents M: Multiply D: Divide A: Addition S: Subtraction Python was designed to use PEMDAS meaning that is Completes parentheses first, than exponents, than multiplication / division, than addition / subtraction.
17
- 17 - SO WH3 dose 3+3*3= 12!!!???!!?!?! Python will follow the steps of PEMDAS so it will look at 3 + 3 * 3 and do the multiplication first so no 3 + 3 * 3 simplifies to 3 + 9, now as you might see 3 + 9 now equals to 12 Lets say you wanted to add 3 + 3 first. You can add parentheses around 3 + 3 to tell python that you want it to combine those first. –(3 + 3) * 3
18
- 18 - Practice Try to guess what the outputs for these math operations –2 + 3 * 4 –(10 + 5 / 5) * 11 –( (12 - 12) * (13 + 31 / 3) ) * 213
19
- 19 - More Math Operations Lets say you wanted to use exponents. For example 2 ⁴. Well because it took me 3 minutes to type ⁴, there is a special sign that means “to the power” of and it is ** so instead of 2 ⁴ we have to type 2**4 but they mean the same thing. Try to guess these outputs keep in mind They still apply to the order of operations. –2 ** 2 + 2 –3 ** (1 + 1) –(11 + 1) ** (1 * 3 - 1)
20
- 20 - Different Types of Numbers Python has several types of numbers. –(int) Integers: numbers without decimal points and has a range from -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 aka really big number. –(float) floating point number: It a type of number that contains decimle places and has larger maximum and minimum values. (These numbers are dependent on the type of computer aka 64 bit vs 32 bit)
21
- 21 - Int Type Operations Ints by them selves have some specific advantages than floats. Like takes up less memory to store, is faster when running python programs, and can be used for other things that we will get in to later. But keep In mind that when you type any number without decimal places Python will assume its an int 7 #this is considered an int 7.0 #this is not considered an int
22
- 22 - Floats Floats are useful in storing really large and small numbers. Also Floats are considered precise meaning that you can have a number like 0.00000000001337. Floats are defined with a decimal place in a number. –3.1415 #is a float –7.0 #is a float –7. #is a float –7 #is not a float
23
- 23 - Even More Maths There are two types of division in python. One defined as / and another defined as //. The first one is the slandered division it will divide 3 / 2 and give out 1.5 no problem but a quirk with using the / sign is that the answer will always be in a float. So if you were to divide 3 / 3 the answer will always be 1.0 just like a float. But lets say you didn’t want the.0 after your answer, your gonna have to use the // sign and it will remove all of the numbers after the decimal place and convert it to an int. So 3 // 3 will equal 1; but also keep in mind that any division operation that will give out a decimal will be ignored. For example 3 / 2 will equal 1.5 but 3 // 2 will equal 1. Try these: –3 / 3 –5 / 1 –12 // 4 –12 // 4 / 3
24
- 24 - That’s all Now you should be arithmetic professionals
25
- 25 - Questions & Answers
26
© 2014 Chris Trenkov
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.