Winter 2019 CISC101 2/17/2019 CISC101 Reminders

Slides:



Advertisements
Similar presentations
For loops in programming Assumes you have seen assignment statements and print statements.
Advertisements

CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Today… Strings: –String Methods Demo. Raising Exceptions. os Module Winter 2016CISC101 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Quiz 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
Today… Files from the Web! Dictionaries. Lists of lists. Winter 2016CISC101 - Prof. McLeod1.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Next Week… Quiz 2 next week: –All Python –Up to this Friday’s lecture: Expressions Console I/O Conditionals while Loops Assignment 2 (due Feb. 12) topics:
Today… Loops and Drawing, Cont. –Two slightly more advanced demos. Collections Overview. Winter 2016CISC101 - Prof. McLeod1.
Arrays Chapter 7.
3.1 Fundamentals of algorithms
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
CS 115 Lecture 8 Structured Programming; for loops
CISC101 Reminders Grading of Quiz 4 underway.
Fall 2017 CISC124 9/21/2018 CISC124 First onQ quiz this week – write in lab. More details in last Wednesday’s lecture. Repeated: The quiz availability.
Winter 2018 CISC101 11/9/2018 CISC101 Reminders
CISC101 Reminders Quiz 2 this week.
CISC101 Reminders Quiz 2 this week.
CISC101 Reminders Assn 3 due Friday, this week.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
Winter 2018 CISC101 11/16/2018 CISC101 Reminders
Winter 2018 CISC101 11/19/2018 CISC101 Reminders
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
CISC101 Reminders Your group name in onQ is your grader’s name.
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CISC101 Reminders Slides have changed from those posted last night…
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Winter 2018 CISC101 11/29/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due Friday, this week. Quiz 3 next week.
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
Winter 2018 CISC101 12/5/2018 CISC101 Reminders
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
CISC101 Reminders Quiz 2 this week.
CISC/CMPE320 - Prof. McLeod
Fall 2018 CISC124 2/15/2019 CISC124 TA names and s will be added to the course web site by the end of the week. Labs start next week in JEFF 155:
CISC124 Labs start this week in JEFF 155. Fall 2018
CISC101 Reminders All assignments are now posted.
CMPE212 – Reminders Assignment 2 sample solution is posted.
CISC101 Reminders Assn 3 sample solution is posted.
For loops Taken from notes by Dr. Neil Moore
CISC101 Reminders Labs start this week. Meet your TA! Get help with:
Winter 2019 CMPE212 4/7/2019 CMPE212 – Reminders
CISC101 Reminders Assignment 2 due today.
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
CISC101 Reminders Assignment 2 due this Friday.
Winter 2019 CISC101 4/14/2019 CISC101 Reminders
Introduction to Computer Science
CISC101 Reminders Quiz 1 marking underway.
Winter 2019 CISC101 4/29/2019 CISC101 Reminders
CISC101 Reminders All assignments are now posted.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Winter 2019 CISC101 5/17/2019 CISC101 Reminders
CMPE212 – Reminders Assignment 2 due today, 7pm.
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
CISC101 Reminders Assignment 3 due today.
Winter 2019 CISC101 5/30/2019 CISC101 Reminders
Hossain Shahriar CISC 101: Fall 2011 Hossain Shahriar
Presentation transcript:

Winter 2019 CISC101 2/17/2019 CISC101 Reminders Quiz 1 marking complete. Grades are available in onQ. Assignment 1 sample solution posted. Assignment 2 due a week from today. Quiz 2 next week, as well. Topics listed in Tuesday’s lecture. “for” loops will *not* be on the quiz. See next slide. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Quiz 2 Topics, Updated All Python. Winter 2019 CISC101 2/17/2019 Quiz 2 Topics, Updated All Python. Up to and including today’s lecture: Style Expressions Console I/O Conditionals while Loops Does not include the for loop, “turtle”, range() BIF or slice operator. Same format & rules as for Quiz 1. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Today Continue Iteration or “Loops”: Code a program in class. Winter 2019 CISC101 2/17/2019 Today Continue Iteration or “Loops”: Code a program in class. The “Other” loop syntax – the “for” loop. Use the turtle to illustrate more examples of iteration. (If we have time). Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

In-Class Problem Display all positive numbers in-between two supplied numbers that divide both numbers evenly. “Even division” means zero remainder after division. Winter 2019 CISC101 - Prof. McLeod

Problem Algorithm Obtain both numbers from the user. The values must be >= 1. Assume user enters an integer, but loop back if value not legal. Determine which of the two numbers is the smaller one. Loop a divisor from 1 to the smaller number: If the divisor divides both numbers evenly (use %) then display the divisor. Winter 2019 CISC101 - Prof. McLeod

The Other Loop… The other kind of looping syntax uses the for keyword. It can be more powerful, particularly with collections – producing very compact code. But you could almost always use a while loop instead – it would just take more code to carry out the same operation. We’ll make more use of the for loop later in the course, after we have discussed collections. Winter 2019 CISC101 - Prof. McLeod

for variable_name in iterable : CISC101 The for Loop Syntax: for variable_name in iterable : You make up variable_name iterable can be a collection, such as a string, list, tuple, set or dict. It can also be an object produced by certain BIFs such as reversed() or range(). It can even be a file! Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

The for Loop, Cont. It is still interchangeable with a while loop. These two “snippets” act in the same way: testString = "I like watching videos!" i = 0 while i < len(testString) : print(testString[i]) i = i + 1 for aChar in testString : print(aChar) Winter 2019 CISC101 - Prof. McLeod

Some New Syntax Two new things snuck their way into the code on the previous slide: The len( ) BIF is used with collections and gives you the number of elements in the collection. For a string, it gives you the length of the string. The square brackets: [ ] is called the “slice operator” and returns a single element (or character) or even a range of elements or characters from a collection. Winter 2019 CISC101 - Prof. McLeod

The range() BIF This BIF generates an iterable and is often used with a for loop. Remember our while loop code to display 1 to 20?: i = 1 while i < 21 : print(i) i = i + 1 Equivalent code using the range() BIF instead: for i in range(1, 21) : Winter 2019 CISC101 - Prof. McLeod

range(start, finish, step) The range() BIF, Cont. Full 3 parameter syntax: range(start, finish, step) start is the start value for the sequence. finish the sequence will stop one short of this value. step the step value to be used for the sequence. Winter 2019 CISC101 - Prof. McLeod

The range() BIF, Cont. 2 parameter syntax: range(start, finish) step is assumed to be 1. 1 parameter syntax: range(finish) start is assumed to be 0. See RangeForLoopsDemo.py Winter 2019 CISC101 - Prof. McLeod

Aside - Slice Operator It is placed after a collection (a list, tuple, string, etc.) or a variable that is a collection type. Used as in: [ # ] or [ # : # ] The first syntax gives you the single element at the location specified. The other syntax gives you all elements between the first location and one less than the last location. We will look at this operator again later. Winter 2019 CISC101 - Prof. McLeod

Turtle Graphics The “Turtle” is an easy way of drawing to the screen. CISC101 Turtle Graphics The “Turtle” is an easy way of drawing to the screen. One use is to illustrate how loops work. See the first section in “Program Frameworks” in the Python Standard Library. To start you’ll need to import the turtle module: from turtle import * Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

A Few turtle Commands To make the turtle look like a “turtle”: shape(“turtle”) To set the line thickness and line colour: pensize(5) pencolor(“green”) The turtle starts out at the “home” position, (0, 0), facing right or “east”. To draw, just issue commands to move the turtle. Winter 2019 CISC101 - Prof. McLeod

A Few More turtle Commands Turning: right(num_degrees) # clockwise left(num_degrees) # counter-clockwise Moving in the direction he is pointing; forward(length) Changing speed: speed(5) # 0 is no animation, 1 slow 10 fastest Winter 2019 CISC101 - Prof. McLeod

turtle Demos Start with five demo programs that illustrate turtle commands. These five do not have any iteration. Start with TurtleDemo1.py Winter 2019 CISC101 - Prof. McLeod

Filling Commands Use begin_fill(), then draw, followed by end_fill() to fill a closed, drawn area. See TurtleDemo2.py See TurtleDemo3.py to see how to draw a filled circle. Winter 2019 CISC101 - Prof. McLeod

Regular Polygons Modify how circle() is invoked to draw regular polygons instead of circles. See TurtleDemo4.py Draw text, too! See TurtleDemo5.py Fun! Winter 2019 CISC101 - Prof. McLeod