Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
Variables Conditionals Loops The concept of Iteration Two types of loops: While For When do we use them? Iteration in the context of computer graphics.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Introduction to Computing Science and Programming I
Loops (Part 1) Computer Science Erwin High School Fall 2014.
16-May-15 Sudden Python Drinking from the Fire Hose.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Python November 14, Unit 7. Python Hello world, in class.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
6/28/2015 1R. Smith - University of St Thomas - Minnesota CISC 130: Today’s Class History Paper recapHistory Paper recap Finish the movieFinish the movie.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
“But I don't want to be a “programmer!” ActionScript for journalists Presentation by Mindy McAdams Flashjournalism.com.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
1 CS 177 Week 5 Recitation Slides Loops. 2 Announcements Project 2 due next Thursday at 9PM. Exam 1 this evening (switch and loop not covered) Old exams.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 9, 2015)
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Engineering 1020 Introduction to Programming Peter King Winter 2010.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
April 6, 1998CS102-02Lecture 2-1 Java Operators CS Lecture 2-1 Being a Smooth Operator.
7 A&F 1.1 OBJECTIVE Use variables & operations to write an expression We LOVE Mathematical Language!!!
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
PHY281 Scientific Java Programming LoopsSlide 1 Loops In this section we will learn how to repeat a series of instructions using loops and to use this.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #001 (January 17, 2015)
Research Topics in Computational Science. Agenda Survey Overview.
1 CS161 Introduction to Computer Science Topic #9.
Recursion Pepper. Another way to loop Call yourself repeatedly until you say to stop. Example: add up 10 numbers using addUp. -- Input – number to count.
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
Solving Linear Equations. Example 1 It’s obvious what the answer is. However, we need to start with the basics and work our way up because we need to.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
CPSC 217 T03 Week V Part #1: Iteration Hubert (Sathaporn) Hu.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 10 Iteration: Loops 05/02/09 Python Mini-Course: Day 3 - Lesson 10 1.
Introduction to Computing Concepts Note Set 14. What if… You had to print “I love Java” to the screen 125 times. How? 125 lines of ▫ System.out.println(“I.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
ORDER OF OPERATIONS. Did you get one of these numbers as an answer? 18? 12? SOLVE THIS PROBLEM.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Programming Fundamentals. Summary of Previous Lectures Phases of C++ Environment Data Types cin and cout.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Lesson 05: Iterations Class Chat: Attendance: Participation
ECS10 10/10
Primitive Data, Variables, Loops (Maybe)
Selection CIS 40 – Introduction to Programming in Python
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
Coding Concepts (Basics)
IST256 : Applications Programming for Information Systems
Algorithms computer as the tool process – algorithm
CISC101 Reminders All assignments are now posted.
Loops.
Repetition Statements (Loops) - 2
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
While Loops in Python.
Class code for pythonroom.com cchsp2cs
Software Development Techniques
Presentation transcript:

Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)

- 2 - Objectives Some review We will be going into increment operators We will also do some loopage Then we will make some awsome programs Questions & Answers

- 3 - Incrementing numbers In most programming languages there is a way to increment variables. This mean the variable can equal one more than it previously did. For example if I want to increase var, which equals 10, by 2, var will equal 12. That is pretty much it.

- 4 - Incrementing with out increment operations How would you increase the values of a variable by 10 when the variable equals 3.

- 5 - Here This is normally the way to do it. It is ugly and has no mother.

- 6 - Basic increments The first type of increment is the += you use the plus equals to increment the values by the operator next to it.

- 7 - Decrement Lets say you want to decement the variable, make it one less, you use the -=, less than equals. It does the same thing except it minuses the current values of the variable by the number next to it.

- 8 - More types in increments You can increment the values using any operation like Var += 2: adding Var -= 2: subtracting Var *= 2: multiplying Var /= 2: dividing Var //= 2: divide rounding Var **= 2: taking it to the exponent, play around with these

- 9 - Fun exarcises Here are some intuitive conversions str(12) int(7.5) float(7) int(“-12”) Here are some not so intuitive, try to guess them str(False) Int(True) float(false) bool(0) bool(1) bool(1337)

Loops In every single useful programming language there are things called loops. A loop is a thing, like an instatement where as if the conditions are true it loops a block of code until they arn't true.

Loops the types In python there are 3 different types of loops, the while loop, the do while loop, and the for loop. For today were are only going to learn the while and the for loop. They are effectively the but are used for different things.

While loop A while loop it the most basic type of loop. It takes in a boolean value, if its true it loops, if it isn't it stops looping. That is as basic as it gets.

How to write a while loop Three steps. Step one: type while Step two: put the buns and the sesame seeds, while(): Step three: fill the buns with a boolean.

Example This is my example, guess what's going to happen

Example 2 If you guessed nothing, you would be right. Because the boolean is false it dosn’t loop or let anything in. Guess what is going to be the output of this

- 16 -

What happend Because the while loop is true it looped the print statement over and over again, and because the True statement will never become false it will loop for ever. Because it loops for ever it will never reach to that print statement down they’re.

Write your own Write your own infinite loop and do something creative with it. If it works don’t do anything. Let it be.

Using the increment operator with it. Lets combined with what we have learned and make a infinite loop with a variable incrementing by one every loop. Then print it out. You can see the speed of the computer. But this is not its fastes speed possible, the print statement takes python a couple of milliseconds to perform so obviousy this is not the true speed of the computer.

Useful while loops Lets write a useful while loop. I’m going to make mine increment x to a million then exit the loop and print out x. you can see the logic, as x is less than one million it will loop again, until x is equal to or greater than it will exit the loop and print x, guess how long this operation will take.

For loops A for loop is a more useful loop with using numbers instead of booleans. You basically declare a variable and give it a range to loop by,

Writing For loops This is a five step process, so be carful. There are more complicated types of for loops used for different things like functions, lists, tuples, and dictionaries. But this is what well use.

For loops Basically what this does is as long as x is in range of the range(), it will continue to loop and increments x by one. You can see this behavior when you print x inside the loop. You can type the same.

For loops Type your own for loop. Make your variable increment by the for loop x every loop then print it out. Try doing this between 0, and one million.

Fibonacci sequence. What is the Fibonacci sequence, It is basically a sequence that starts with 0, and 1, it then adds the two numbers together making 1, it then adds the sum to the previous number, 1, making 2, it then adds 2 to the pervious number. It does this.

Fibonacci sequence. Example use of for loop

Seriously????!!?!?!? Are there any questions, or concerns, would you like me too explain something again, This is the most fundamental part of programming, and is what allows you to do some really awesome things later down the line

Questions & Answers

© 2014 Chris Trenkov