class 4 definite loops range list end=" "

Slides:



Advertisements
Similar presentations
Advanced Programming 15 Feb The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Adapted from John Zelle’s Book Slides
Python Programming: An Introduction to Computer Science
CSC 110 Writing simple programs [Reading: chapter 2] CSC 110 C 1.
Vahé Karamian Python Programming CS-110 CHAPTER 2 Writing Simple Programs.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
1 Functions Samuel Marateck © A function is a set of statements that can be referred by the function name. To start writing a function. 1. In the.
Chapter 2 Writing Simple Programs
Review Algorithm Analysis Problem Solving Space Complexity
Computer Science 111 Fundamentals of Programming I Iteration with the for Loop.
9/8/ Relations and Functions Unit 3-3 Sec. 3.1.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 1 Computers and Programs.
The Python interpreter CSE 140 University of Washington Michael Ernst.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
Sorting and Modules. Sorting Lists have a sort method >>> L1 = ["this", "is", "a", "list", "of", "words"] >>> print L1 ['this', 'is', 'a', 'list', 'of',
For loops in programming Assumes you have seen assignment statements and print statements.
Math – What is a Function? 1. 2 input output function.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
IDLE An IDE for Python bundled with the program release Click on IDLE (Python GUI) in the Start menu under the Python program group  Get the IDLE Python.
Debuggers in Python. The Debugger Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
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.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
CS 177 Week 10 Recitation Slides 1 1 Debugging. Announcements 2 2.
4.2 Patterns and Linear Functions I can identify and represent patterns that describe linear functions.
Python Basics  Functions  Loops  Recursion. Built-in functions >>> type (32) >>> int(‘32’) 32  From math >>>import math >>> degrees = 45 >>> radians.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Loops and Simple Functions COSC Review: While Loops Typically used when the number of times the loop will execute is indefinite Typically used when.
An introduction to the debugger And jGrasp editor-syncrasies (ideosyncrasies)
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
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 – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
Chapter 2 Writing Simple Programs
IE 8580 Module 4: DIY Monte Carlo Simulation
Pseudocode Key Revision Points.
Topic: Iterative Statements – Part 1 -> for loop
Introduction to Programming
Python: Experiencing IDLE, writing simple programs
Lesson 4 - Challenges.
Python Programming: An Introduction to Computer Science
Think What will be the output?
Procedures Programming Guides.
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Count Controlled Loops (Nested)
Intro to Nested Looping
1.6 Represent Functions as Rules and Tables
Multiple Selections (ELIF Statements)
Variables Table counter = 1 while counter < 4: print("Happy days") counter = counter + 1 print(“End of program”) What is printed?
A mini TRACS.
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Introduction to Programming
Reading Python Code Students will identify the parts of a Python program Students will describe the history of the computer bug. Students will look at.
Elements of a Python Program
Intro to Nested Looping
Python programming exercise
jGRASP editor-syncrasies (idiosyncrasies)
Python Basics with Jupyter Notebook
CSCI N207 Data Analysis Using Spreadsheet
class 5 retrieving a previous statement in Thonny or IDLE // %
Loops and Simple Functions
Basic Lessons 5 & 6 Mr. Kalmes.
For Tutors Introduce yourself.
Control Operations Basic operations are input, output, arithmetic, etc. Control operations allow for sequencing other operations Choose between several.
Topic: Loops Loops Idea While Loop Introduction to ranges For Loop
Introduction to Programming
The Python interpreter
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
Presentation transcript:

class 4 definite loops range list end=" " in loop, after loop – indentation matters simultaneous assignment simultaneous input using the debugger in thonny retrieving previous statement in thonny or IDLE shell

module doesn't print without a print statement (ie, nothing like >>>a) In shell: >>>x=3 >>>x 3 In module: x=3 x no output

definite loop

for i in range(5): print("i=",i)

for i in range(5): print("i=",i) i= 0 i= 1 i= 2 i= 3 i= 4

CODE for k in range(5): print(2*k, end=" ")

CODE for k in range(5): print(2*k, end=" ") OUTPUT 0 2 4 6 8

CODE for k in range(5): print(2*k+1, end=" ")

CODE for k in range(5): print(2*k+1, end=" ") OUTPUT 1 3 5 7 9

CODE m = 5 for k in range(m): print(100+2*k+1, end=", ") print(100+2*m+1)

CODE m = 5 for k in range(m): print(100+2*k+1, end=", ") print(100+2*m+1) OUTPUT 101, 103, 105, 107, 109, 111

CODE m = 5 for k in range(m): print(100+2*k+1, end=", ") print() print(100+2*m+1)

CODE m = 5 for k in range(m): print(100+2*k+1, end=", ") print() print(100+2*m+1) OUTPUT 101, 103, 105, 107, 109, 111

CODE m = 5 for k in range(m): print(100+2*k+1, end=", ") print() print(100+2*m+1)

CODE m = 5 for k in range(m): print(100+2*k+1, end=", ") print() print(100+2*m+1) OUTPUT 101, 103, 105, 107, 109, 111

Indentation Matters! CODE m = 5 for k in range(m): print(100+2*k+1, end=", ") print() print(100+2*m+1) OUTPUT 101, 103, 105, 107, 109, 111 Indentation Matters!

CODE for k in [101, 103, 105, 107, 109]: print(k, end=", ") print() print(111)

CODE for k in [101, 103, 105, 107, 109]: print(k, end=", ") print() print(111) OUTPUT 101, 103, 105, 107, 109, 111

What if I asked for odd numbers 101 to 1001? CODE for k in [101, 103, 105, 107, 109]: print(k, end=", ") print() print(111) What if I asked for odd numbers 101 to 1001? OUTPUT 101, 103, 105, 107, 109, 111

CODE list(range(4))

CODE list(range(4)) OUTPUT [0, 1, 2, 3]

Simultaneous Assignment (draw memory) long, lat = 43.0, 76.1 month, day, yr = eval(input("month, day, year"))

Debugger review an example view the variables area debug, step over, step into

retrieving previous statements in the shell. In Thonny, up and down arrow keys. In IDLE: mac: control p (previous), control n (next) windows: alt p, alt n