(Monty) Python for loops Mr. Neat. Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide()

Slides:



Advertisements
Similar presentations
Chapter 4 - Control Statements
Advertisements

This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Control Structures. Decision Making Structures The if and if…else are all selection control structures that introduce decision-making ability into a program.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
Computer Science 1620 Loops.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
1 CS 105 Lecture 8 Strings; Input Failure Mon, Mar 7, 2011, 3:39 pm.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Starting out with C++1 Chapter 9 – Pointers Getting the address of a Variable Why do we have pointers? Indirection – difference between –Will you go out.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
1 Python Chapter 4 Branching statements and loops © Samuel Marateck 2010.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
Chapter 4: Looping CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Chapter 6 – Repetition Statements : Objectives After you have read and studied this chapter, you should be able to Implement repetition control in a program.
Control Structures FOR Statement Looping.
Lecture 4 Introduction to Programming. if ( grade ==‘A’ ) cout
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
For loops in programming Assumes you have seen assignment statements and print statements.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 2.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
INPUT & VARIABLES.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Nested for loops.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
The for loop.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Computer Science 101 For Statement. For-Statement The For-Statement is a loop statement that is especially convenient for loops that are to be executed.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
FOR LOOPS "LOOP FOR A SET NUMBER OF TIMES.". FOR ( START_VALUE; END_VALUE; INCREMENT_NUMBER ) { //YOUR_CODE_HERE } So after the word "for" (in lowercase)
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
More about Iteration Victor Norman CS104. Reading Quiz.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
FIND THE VOLUME: 5 in 8 in 4 in.
GCSE COMPUTER SCIENCE Practical Programming using Python
Java for Beginners.
Lesson 3 - Repetition.
While Loops.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Introduction to pseudocode
Introduction to Programming
Validations and Error Handling
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
An Introduction to Python
Chapter 8 The Loops By: Mr. Baha Hanene.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Class Examples.
Looping III (do … while statement)
Loops.
Python Basics with Jupyter Notebook
CS 101 First Exam Review.
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
More Basics of Python Common types of data we will work with
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Computer Science Club 1st November 2019.
Presentation transcript:

(Monty) Python for loops Mr. Neat

Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide() ) functions ( gotoxy(4,3) ) functions ( str(5) ) output new Text(“ “,,, ) System.out.print() cout << print(“ blah, blah”) input skipped this (complicated) cin>> input( ) casting int( ) int(double) int(string) if - else if(boolean) { } else { } brackets replaced by indenting! if(boolean) { } else { }

Strings Again Python considers a string as a collection of characters. There is a Python function that determines the number of characters in a string…. len(put string in here)

Comparison JavaC++Python for loops for( int i=0 ;i<10 ; i++) exact same as Java different

Strings again >>> temp = “surfer dude” >>> print(len(temp))

Strings again surfer dude answer

for loops in Python Same idea as C++ and Java – provides a mechanism for repeated actions Syntax different from C++ and Java Requires a list We are using a list of numbers via the range() function

range function range(num1, num2) creates the list of numbers from num1 (and including it) to num2 (but not including it) incremented by ones For example, range(0,4) produces the list 0,1,2,3

for loops in Python >>> for x in range(0,4): print(x) How would we list the numbers 0 through 3?

for loops in Python - explanation for each number in the list, write the number to the screen

More on print() function print(“*”) output: *

More on print() function print(“*”,end=‘ ‘) print(“*”) output: **

Lab 8 Write an app that draws a line. Ask the user for line length and if they want a horizontal or vertical line. Example output: Please enter line length: 4 Do you want a horizontal or vertical line? vertical *