Lecture 3: Conditionals and Loops

April 3, 2020

Downloads

Session log

Luis Perez
2020-04-03 08:59:31
"***Class started***"
Maggie Weitzman
2020-04-03 09:01:10
"403 Forbidden zoom"

Joseph Harman
2020-04-03 09:02:39
Looks like most people have gotten in - I'd try logging out of zoom, closing it, and re-clicking link?

Cori Cahoon
2020-04-03 09:03:04
Also restarting your computer has worked for me in the past too.
👍1

Maggie Weitzman
2020-04-03 09:03:30
I just restarted right before meeting because I was getting audio failure

Maggie Weitzman
2020-04-03 09:03:32
uugghhh

Maggie Weitzman
2020-04-03 09:04:18
Still forbidden

Joseph Harman
2020-04-03 09:05:21
Try these zoom update steps: https://www.businessinsider.com/how-to-update-zoom they've been changing a lot of stuff lately due to hacking, issues, etc

Maggie Weitzman
2020-04-03 09:06:16
I am not using the client (crashes/freezes), so I have been using the browser interface. Still need to update the client ??

Joseph Harman
2020-04-03 09:07:37
Honestly not sure...are you using chrome? looking into it now

Maggie Weitzman
2020-04-03 09:07:50
yes using chrome

Maggie Weitzman
2020-04-03 09:08:15
using the method mike & i troubleshooted on Tuesday...worked for Wed class...now not working .... whhhhyyyy? this is a brand new computer! 😞

Maggie Weitzman
2020-04-03 09:13:07
Ok, I've restarted several times. Still 403 forbidden. Sorry I'm missing class (again).

Maggie Weitzman
2020-04-03 09:17:08
I'll continue working on the chapters myself and trying to answer polls/questions

Joseph Harman
2020-04-03 09:21:05
Sorry 😞 I'll keep looking around on the internet, not quite sure how to troubleshoot zoom browser interface. My default is to restart/update everything - zoom, laptop, etc - but it sounds like you've been doing most of that

Maggie Weitzman
2020-04-03 09:22:07
Yep, been doing all that. The frustrating thing is my audio is working fine today (that was an issue earlier this week) but I just can't get into the meeting! I appreciate your help though.

Joseph Harman
2020-04-03 09:24:32
maybe try downloading and using zoom app? I know it's been freezing on you in the past, but maybe current updates will work. zoom browser apparently has more limited functionality.

Maggie Weitzman
2020-04-03 09:49:07
I downloaded the app and got into the meeting without freezing (wtf zoom). Now I am behind the class and having trouble following. Ha!

Joseph Harman
2020-04-03 09:50:19
We're still basically on the 03_conditionals notebook at the moment
Maggie Weitzman
2020-04-03 09:02:04
Are other people able to join? I am getting error message
Luis Perez
2020-04-03 09:04:31
“**Entering breakout rooms**”
Cathy Robinson
2020-04-03 09:04:39
I’m alone in my breakout room?
Roz Carrier
2020-04-03 09:04:42
I'm by myself in breakout room
Dillon Willis
2020-04-03 09:04:43
I’m alone as well!
Katie Fisher
2020-04-03 09:04:45
I am alone too
Michael Shavlik
2020-04-03 09:05:48
People will be coming!
Mike Harms
2020-04-03 09:07:40
Okay, you should all now be in breakout rooms. Luis is about to post three questions (a poll and two thread starters) for you to answer. I’ll check in 5 minutes…
Luis Perez
2020-04-03 09:07:49
Share one new thing you learned from the 03_conditionalsnotebook? (Reply in thread.)

Andrew Holston
2020-04-03 09:21:21
I'd known of else and if separately before, but elif was new to me; it seems rather useful.

Lila Kaye
2020-04-03 09:21:24
the 'and' operator requires both sides to be True, it wont work if both sides are False (even though thats the same on both sides)
Luis Perez
2020-04-03 09:08:09
What are you still confused about in the 03_conditionalsnotebook? (Reply in thread.)

Amber Rolland
2020-04-03 09:09:51
not confused really, just curious. are there other ways to use and, or, & not? in C++ for example, you use && for and, || for or.

Maggie Weitzman
2020-04-03 09:16:03
I am getting a syntax error on this line and I can't figure out why: elif x = 0: print(b)

Luis Perez
2020-04-03 09:16:48
Try indenting the line print(b)

Maggie Weitzman
2020-04-03 09:17:24
It is indented (sorry that didn't copy/paste)

Luis Perez
2020-04-03 09:17:39
I see it now, x == 0

Maggie Weitzman
2020-04-03 09:17:52
ooooohhhh Ok. thanks!!

Luis Perez
2020-04-03 09:17:52
if you put only x = 0 it won't work

Maggie Weitzman
2020-04-03 09:18:45
Ok now I get a different error. here is my code:

Maggie Weitzman
2020-04-03 09:18:57
x = -2 if x < 0: print(a) elif x == 0: print(b) else: print(c)

Maggie Weitzman
2020-04-03 09:19:02
(with indents)

Maggie Weitzman
2020-04-03 09:19:12
NameError: name 'a' is not defined`

Luis Perez
2020-04-03 09:19:30
okay, try print ("a"), because right now you're trying to print a variable that's not defined

Maggie Weitzman
2020-04-03 09:20:07
ok, needs quotes. got it

Maggie Weitzman
2020-04-03 09:20:28
Thanks Luis - zoom is not working for me (again) so I'm working through the notebooks on my own.
Polly Poll
2020-04-03 09:08:46
Poll by @Luis Perez
I would rate my understanding of the material in the 03_conditionalsnotebook as:
😱⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
🙁⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
😐⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
🙂⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
😄█████████████████████████25
Cathy Robinson
2020-04-03 09:10:22
So, where should we be staring in the breakout rooms right now? 05_lists?
Cathy Robinson
2020-04-03 09:10:30
*starting
Mike Harms
2020-04-03 09:10:58
You should start at 03_conditionals.
Cathy Robinson
2020-04-03 09:11:07
great- thanks!
Cathy Robinson
2020-04-03 09:11:20
(that’s what we thought 😉 )
👍1
Polly Poll
2020-04-03 09:12:38
Poll by @Mike Harms
Figuring out timing: I think we need _____ in the breakout room
no█████████████ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢13
5████████ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢8
10███ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢3
Zach Garrison
2020-04-03 09:14:31
Hey we're a little confused on what the "continue" command does. Anybody got a good explanation?

Mike Harms
2020-04-03 09:14:57
Want to add this to the “I’m confused about” thread above?
Mike Harms
2020-04-03 09:14:44
@everyone: I’m going to end breakout room at 9:19. Please answer the threads and polls above with questions.

Mike Harms
2020-04-03 09:16:06
They were made by @Luis Perez
Luis Perez
2020-04-03 09:20:06
**Leaving breakout rooms.**
Dillon Willis
2020-04-03 09:41:46
👀
Luis Perez
2020-04-03 09:41:51
i = 0 while i > -2: i = i+1 print(i) if i > 10: break```
Polly Poll
2020-04-03 09:42:16
Poll by @Luis Perez
If I ran the code above, I would see:
*1*:█ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢1
*2*:⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
*3*:█████████████████ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢17
*4*:█████ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢5
Luis Perez
2020-04-03 09:44:21
import math x = -2 if x < 0 and math.abs(x) > 5: print("option 1") elif x < 2 or x > 2: print("option 2") else: print("option 3")```
Polly Poll
2020-04-03 09:45:23
Poll by @Luis Perez
What would the code block above print?
option⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
option█████████████████████████25
option⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
Luis Perez
2020-04-03 09:50:53
**Entering breakout rooms**
Luis Perez
2020-04-03 09:51:04
Share one new thing you learned from the 04_oopsnotebook? (Reply in thread.)

Laura Desban
2020-04-03 09:52:06
The command range and how it functions in Python

Patrick Connor
2020-04-03 09:54:52
How to determine a sum in Python

Natanya Villegas
2020-04-03 09:56:11
I learned about how start, end, and step values can be set for command range and how that can be used within a loop.

Zach Garrison
2020-04-03 10:00:21
how to set ranges and calculate sums for those ranges

Acadia DiNardo
2020-04-03 10:01:32
how to set upper and lower limits and calculate the sum just in those ranges

Abbey Lasseigne
2020-04-03 10:02:59
I learned that continuein a loop ends the current iteration and starts the next one where as `break` stops the looping altogether

Cori Cahoon
2020-04-03 10:04:19
how to sum up a range without using a loop

Lauren Lehmann
2020-04-03 10:05:05
I learned that if you multiply by 0 your while loop will just spit out infinite 0s

Roz Carrier
2020-04-03 10:10:20
How to use range, while and breaks

Hannah Markovic
2020-04-03 10:12:41
“Continue” will skip to the next iteration of the loop

Sophia Phillips
2020-04-03 10:56:19
The magic of indentations (how they make commands relevant to different parts of your loop)

Elena Wall
2020-04-03 11:02:21
I learned that placement of "break" and "continue" matters as does indentation!

Jon Muyskens
2020-04-03 11:17:13
I also learned the importance of indentations
Luis Perez
2020-04-03 09:51:14
What are you still confused about in the 04_loopsnotebook? (Reply in thread.)

Zach Garrison
2020-04-03 09:53:49
i'm confused what continue does

Luis Perez
2020-04-03 09:54:19
It sends you back to the beginning of the loop

Luis Perez
2020-04-03 09:54:43
essentially bypassing whatever was written after continue

Natanya Villegas
2020-04-03 09:56:53
Still confused about how to write a loop that calculates a sum.

Tory Herman
2020-04-03 09:57:06
when to use while and when to use for

Zach Garrison
2020-04-03 09:58:31
how does python know to calculate the sine values every pi/4? We didn't explicitly outline the range of values and it doesn't seem like pi/4 would fit within the same every integer range like with previous codes.

Patrick Connor
2020-04-03 09:58:35
Continue keyword
👍2

Tory Herman
2020-04-03 09:58:41
also, my program was unable to calculate sin of pi as zero - instead it was a tiny non-zero answer
👍1

Vickie
2020-04-03 10:01:39
How to print out just the final sum rather than list of all x+1 values

Lauren Lehmann
2020-04-03 10:06:24
Mine also doesn't round sin(pi) to 0 and I'm not sure why

Abbey Lasseigne
2020-04-03 10:13:33
x = 0 for i in range(1,100001): x = x + i #print(x) if x > 30000: break print(x)``` Result: 30135

Abbey Lasseigne
2020-04-03 10:14:02
How do we get it to only print the last number before it hits 30000?

Luis Perez
2020-04-03 10:38:25
@Abbey Lasseigne here's a very inelegant solution, keep track of the number with a variable y, assign that value to the desired variable before y = y+i import math number_before = 0 y = 0 i = 0 for i in range(100001): if y < 30000: number_before = y y = y + i else: break print(number_before)```
👍2

Luis Perez
2020-04-03 10:55:46
A more elegant solution: x = 0 for i in range(1,100001): x = x + i if x + i > 30000: break print(x)```
Polly Poll
2020-04-03 09:52:15
Poll by @Luis Perez
I would rate my understanding of the material in the 04_loopsnotebook as:
😱⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
🙁⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ 0
😐███ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢3
🙂████████████████ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢16
😄█████ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢ ⁢5
Tory Herman
2020-04-03 09:54:22
when to use while vs. for

Michael Shavlik
2020-04-03 10:50:57
A general response that I've heard for this, is that you would use a while loop when you *don't* know how long your loop is supposed to go for (e.g. you don't have a defined range of numbers that you know you need to loop over). If you have a defined length file, or a specific range (e.g. 0,101), you would use a for loop

Tory Herman
2020-04-03 10:58:20
cool - thnx!
Ryan Swan
2020-04-03 09:57:31
elif is essentially an if statement within an if statement (maybe...?)
Mike Harms
2020-04-03 09:58:13
@everyone: please post if you want a TA to drop into your breakout room! 🙂

Lila Kaye
2020-04-03 10:03:32
We do
👍1

Cathy Robinson
2020-04-03 10:07:44
we do too
👍1
Philip Nosler
2020-04-03 09:59:29
Can a TA join us in our breakout room? Sorry, I'm not sure which one we're in.
👍1
Jon Muyskens
2020-04-03 10:04:07
Can a TA join Lila and me in our breakout room.
👍2
Cathy Robinson
2020-04-03 10:07:58
We could use some TA help
👍1
Mike Harms
2020-04-03 10:13:32
I’m going to end the breakout rooms at 10:17
Luis Perez
2020-04-03 10:17:41
***Leaving breakout rooms***
Luis Perez
2020-04-03 11:01:03
**Class ending**