CISC101 Reminders Quiz 1 marking underway.

Slides:



Advertisements
Similar presentations
Dr. Yang, Qingxiong (with slides borrowed from Dr. Yuen, Joe) LT4: Control Flow - Loop CS2311 Computer Programming.
Advertisements

Computer Science 1620 Loops.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
Loops – While, Do, For Repetition Statements Introduction to Arrays
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.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Control Flow Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
CPS120 Introduction to Computer Science Iteration (Looping)
Spring 2006CISC101 - Prof. McLeod1 Announcements Assn 4 is posted. Note that due date is the 12 th (Monday) at 7pm. (Last assignment!) Final Exam on June.
COMP Loop Statements Yi Hong May 21, 2015.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Today… Python Keywords. Iteration (or “Loops”!) 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.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. 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:
Computer Programming -1-
CprE 185: Intro to Problem Solving (using C)
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
The switch Statement, and Introduction to Looping
JavaScript: Control Statements I
Control Statements Kingdom of Saudi Arabia
JavaScript: Control Statements.
JavaScript: Control Statements I
Incrementing ITP © Ron Poet Lecture 8.
Winter 2018 CISC101 11/9/2018 CISC101 Reminders
Winter 2018 CISC101 11/9/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due Friday, this week.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
Looping and Repetition
Control Structure Senior Lecturer
Outline Altering flow of control Boolean expressions
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
Winter 2018 CISC101 11/27/2018 CISC101 Reminders
Winter 2018 CISC101 11/29/2018 CISC101 Reminders
A First Book of ANSI C Fourth Edition
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
CISC101 Reminders Quiz 2 this week.
Iteration: Beyond the Basic PERFORM
3 Control Statements:.
Chapter 3 – Control Structures
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
CISC124 Labs start this week in JEFF 155. Fall 2018
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
CMPE212 – Reminders The other four assignments are now posted.
CISC101 Reminders All assignments are now posted.
CMPE212 – Reminders Assignment 2 sample solution is posted.
CISC101 Reminders Labs start this week. Meet your TA! Get help with:
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
Loops.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
CISC101 Reminders Assignment 3 due today.
Hossain Shahriar CISC 101: Fall 2011 Hossain Shahriar
REPETITION Why Repetition?
Looping and Repetition
Presentation transcript:

CISC101 Reminders Quiz 1 marking underway. Winter 2019 CISC101 4/23/2019 CISC101 Reminders Quiz 1 marking underway. Assignment 2 due a week from Friday. You have all the lecture material you need for this assignment. Style will be graded this time. Quiz 2 next week, as well. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Quiz 2 All Python. Up to and including this Friday’s lecture: Expressions Console I/O Conditionals while Loops for Loops Does not include the “turtle”. Same format & rules as for Quiz 1. Winter 2019 CISC101 - Prof. McLeod

Today Continue Iteration or “Loops”. Winter 2019 Winter 2019 CISC101 4/23/2019 Today Continue Iteration or “Loops”. Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

while loop - Cont. while loop syntax: while boolean_expression : line1 line2 … As long as boolean_expression is True, the statements in the loop continue to execute. Winter 2019 CISC101 - Prof. McLeod

Summing Numbers Demo Obtain any number of numbers from the user, sum them up and then display the average of the numbers. (Ignore the possibility of non-numeric input.) How do we stop such a process? See SumNums.py Winter 2019 CISC101 - Prof. McLeod

SumNums.py Example, Cont. Shows a different way of stopping a loop that does not use a incrementing variable. Is this the only way to control the loop in this case? Are there other conditions that you could use? Also demonstrates the use of an if statement inside a loop. The if statement is executed once for every iteration of the outer loop. Winter 2019 CISC101 - Prof. McLeod

Four More Loop Keywords break, continue, else, pass else and pass are used in other places too. Should not be used very often! Winter 2019 CISC101 - Prof. McLeod

Use of break and continue With Loops CISC101 Use of break and continue With Loops Don’t use these keywords unless you feel it makes your code easier to read and debug! break exits a loop immediately continue jumps to the next iteration immediately. See BreakContinueDemo.py Does break kick you out of a nested loop? Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Use of else and pass With Loops else with a loop gives you a chance to see how the loop exited - if a normal exit, the else is executed. See LoopElseDemo.py pass is used when a statement is required, but you don’t have anything you want to do! (Or you have not yet written the code.) See PassDemo.py Winter 2019 CISC101 - Prof. McLeod

Natural Logs Demo Uses a numerical technique to estimate the value of natural logs. Explain what natural logs are first, and then look at the infinite series (a Taylor’s series) used for the calculation. How to stop the calculation loop? You are not responsible for the math or the code in this demo Winter 2019 CISC101 - Prof. McLeod

Another Demo - Natural Logs (Math!) Consider log10 first: This is the power of 10 that gives you a certain number. For example log10(100) is 2 since 102 is 100. Natural logs don’t use base 10, they use base e, where e is 2.718281828459045 The natural log function is usually called “ln()” (but in Python it is math.log(). Base 10 log is called as math.log10().) Winter 2019 CISC101 - Prof. McLeod

Demo – Computing Natural Logs Here is a series to compute natural logs: or: Using x = 1/3 will provide ln(2), for example. Winter 2019 CISC101 - Prof. McLeod

Computing Natural Logs, Cont. To calculate the natural log of any number, y, where y is greater than one, you can first calculate x using: As you can see, x will always be less than 1. Winter 2019 CISC101 - Prof. McLeod

Computing Natural Logs, Cont. The natural log is not defined for values of y less than or equal to zero. But if y is between zero and one – a fractional value – calculate the log of 1/y and negate it: Winter 2019 CISC101 - Prof. McLeod

Natural Logs Demo Write a program to estimate the natural log of a supplied number, y, where the value must be greater than zero. Display the result and the number of iterations required. Compare your estimated value against math.log(). Winter 2019 CISC101 - Prof. McLeod

CISC101 Natural Logs Demo, Cont. The input part is just like what we have done before, but how does the calculation part work? Since you can’t sum to infinity, how do you decide when to stop? (Note that this is a pretty advanced example!!) See ComputingLogs.py Winter 2019 CISC101 - Prof. McLeod Prof. Alan McLeod

Demo Summary The demo showed how a loop can be used to carry out a serious calculation. And we saw another way to stop a loop which works because floats are limited in size. You should be able to write any of the code in the demo – no advanced code was used, but you do not need to understand the math! Winter 2019 CISC101 - Prof. McLeod