Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)

Similar presentations


Presentation on theme: "Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)"— Presentation transcript:

1 Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)

2 - 2 - Objectives We will be reviewing what we learned last week We will be learning booleans We will also be learning how to do logic in Python Plus, we will make a few more programs Questions & Answers

3 - 3 - Follow Up We learned how to use variables and user Input (which are both very useful!) We went over how to write a calculator program and more

4 - 4 - Lets write more programs! Here is a new programming project you guys can do. Try to make a program that asks you your first name, last name, and age, then making it print out –Hello Chris Trenkov, you are 15 years old Make sure to ask questions when writing your program

5 - 5 - Some Hints Make sure when your asking for the age try to define your input as an integer by doing –Int(input(“Enter Your Age: ”)) Also another place were you might have trouble in is when you print out your statement. Make sure when you print out an int cast it as a string like –Print(“Strings can be added with numbers like: ” + str(varNum))

6 - 6 - This is how I did it

7 - 7 - Lets do something new, like booleans What is a boolean, is that even a word? Maybe some of you who are in pre Calculus, or have worked with programming before might know what it is. After spending 30 seconds Googeling a simple definition for it, I’ve found that that word Isn’t used very much outside of computers or Algebra. Here is my definition: a boolean is a type of statement that is either true or false. That’s is pretty much what it is exactly.

8 - 8 - More On Booleans It might seem like an alien concept, and that is because you haven’t used anything like it. You’ve uses words so strings make sense, and of course you know what numbers are so ints and floats make lots of sense, but you guys have probably never used true or false statements. But trust me its very simple.

9 - 9 - Using Booleans in Python Ok, hear me out... Bust open IDLE and type exactly (make sure you have the capital Python is case Sensitive) –True –False You might of realized you typed something in python without the “” or ‘’ without getting an error. That is because the words True and False are special to Python. They are above the rules. They are better than everyone else. They represent boolean values in python. This is the equivalent of typing numbers in Python without quotations. Numbers are also special to Python they represent Ints/Floats. Just like how True and False represents boolean.

10 - 10 - Comparative Operators Booleans shown in the examples that I have been giving them to you in aren’t useful at all. In python we us things called comparative operators (for numbers) –An example is like 12 > 13 = False –Try typing 12 < 3 3 > 12 13 < 3

11 - 11 - More on Comparative Operators There are more comparative operators in Python than just greater than or less than –There is < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) == (equals to This is a comparative operator not the same as just =) != (not equal to)

12 - 12 - More on Comparative Operators Try typing out your own comparative operations

13 - 13 - What are Booleans used for? Booleans in Python are used for logic, right now we have only been programming using inputs and printing out, We have done nothing with using logic in Python yet. An equivalent of using a boolean in python in the real world is, stating you are 21, The answer to that statement is either True or False, That intern is basically the use for booleans and comparative operators, But how do we do that you ask? We use a thing called an If statements

14 - 14 - Variables What are variables? Are they the same thing as a variable in math? Yes they are, kind of, but better. You can use them to store values and use them later. Open your command prompt / terminal. Then type x = 10. you can then type x again and the number 10 will spit out. This is the most basic example / use for a variable.

15 - 15 - If statements In Most programming languages there is a thing called an If Statement, They are probable the most valuable thing in programming next to variables. They are the reason we can do most things in computers today, so you treat them with love and respect! They allow you to do tests on certain operations and splits the code up to make it more complex

16 - 16 - How do I use an if When you use an if statement you have to do this If(True): Then you press enter and type your print statement (make sure you keep it tabbed) Then when you finish writing the if statement press back to go back a level.

17 - 17 - Why tab In python to section off your code you have to tab, it is sort of this built in feature in Python that forces users to tab their code. It is very important to tab your code, especially when it looks like this

18 - 18 - Now were writing a new program with logic Write a program that asks you your age and then tells you if you are old enough to drink. That’s it!

19 - 19 - Questions & Answers

20 © 2014 Chris Trenkov


Download ppt "Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)"

Similar presentations


Ads by Google