Lecture Materials

Class Announcements

Assignment 2 comes out tomorrow!

Questions & Answers


Q: just a quick question…how do we switch sections?

A1:  Email Tara :)


Q: Was there HW last night? Just asking becasue I didnt see any. Thanks:)

A1:  Assignment 1 is due tonight (Tues, Jun 29th) @ 11:55pm PST. So in approximately 10hrs


Q: I’m sure this has been answered before, but where can we get homework help?

A1:  Fantastic question!! Your first stop should be LaIR which is where you can get 1-1 help from a section leader. The hours for LaIR are M/W 5-7pm and Tu/Th 7-9pm. You can also stop by Juliette or Tara’s office hours (times listed on the website homepage). It’s hard to debug code asynchronously but you can also make a private Ed post or email your section leader.


Q: Is it ok to use other IDE or text editor other than Pycharm?

A1:  We recommend that you use Pycharm because the course is designed to use Pycharm :)


Q: Do we need preconditions and postconditions for each of the helper functions (assuming there is multiple) for each bit problem or a precondition for the program in the beginning and a postcondition at the very end is okay?

A1:  You should have a comment for every function in your program :)


Q: How often are quizzes? Are they every Friday?

A1:  There will be 2 quizzes this summer. Fri, July 9th and Fri, Aug 6th during class time


Q: What the the number stand for in a function parameter?

A1:  mmm can you clarify which number you’re talking about? You can reask your question with the line of code in question


Q: Random question: I was working on my resume where I was writing down which coding languages I was familiar with. Is “Bit” a “language”/“program” we can add?

A1:  Bit is not a programming language on it’s own. It’s based off Python. Once you’re done with the class, you’ll know a lot of Python :)


Q: how does writing the word “left” know we are talking about the number of pixels?

A1:  When the function is called, the caller has to put a number in to indicate the number of pixels. As the function designer we decided to call our second parameter left but we could have choosen any name.


Q: if we dont use left as parameters but we use for x in range(left), will the code run?

A1:  No, you would encounter an error. The computer would not know what left references. You decide which name to call your parameters.


Q: For the checker board program in our Bit homework, I know it's recommended to complete one row and then move down and complete another and so on. Is it okay to do it in columns instead? Because that's how I could easily solve it.

A1:  If your code works and still uses decomposition, you can use columns instead of rows


Q: if I name the function (filename, right), will it still run for left side of the image?

A1:  Yes if you keep all the code the same except any instance where left appeared you changed it to right. You can choose any name for your parameters. You could have named them (pizza, rocks) but that would not be good descriptive names


Q: in darker left the parameter value “left” was based on the case number right?

A1:  Left has a different value in each case. The caller has to put in a number for left when they call the function


Q: Don't RGB values take on integer values? If so, wouldn't multiplying the RGB values by 0.5 run the risk of returning a non-integer value and thus be undefined?

A1:  The computer rounds the float (decimal) number into an integer


Q: is that why when we called helper functions we would put “bit” within the parentheses? bc the helper function is being applied to bit?

A1:  Yes, we had to pass in Bit as a parameter into our helper functions so that the function could modify Bit.


Q: why are there commas in print(‘a:’, a, ‘b:’, b) but the commas do not print out

A1:  Great question! The commas are used to indicate spaces. It’s also a way to put a variable in a print statement since we don’t know the hard coded number. So print(‘a: ‘, a) is saying put the variable value of a into the print statement.


Q: What is exactly is the purpose of the Hack Mode Interpreter?

A1:  It’s a place where you can try things out without having a file and function :) It’s similar to the terminal inside IDEs

A2:  I meant the Python Console on Pycharm. I always confuse those names


Q: What’s the difference between arguments and parameters?

A1:  Great question! Function parameters are the names listed in the function’s definition. Function arguments are the real values passed to the function during a function call


Q: do parameters have to match types? like numbers and strings, boolean

A1:  You can have several different types of parameters inside a function definition. Also, since variables are not explicitly typed you could pass in incorrect types into parameters. You would probably incounter errors if you say pass a string in place of an integer and try to add two strings when they should be integers. I answered a question but maybe not yours so please reask another question if you still need clarification!


Q: For the HW (and in general), when writing a function that is already defined in the instructions, do we need to add our own comments?

A1:  If the function is provided to you fully implemented (i.e. you don’t have to add any code to that function) you do not need to add comments for it unless it is explicitly stated that you do. For any functions that you write, you should write a header comment for it.


Q: is it more conventional to use the comma or + sign in a print statement?

A1:  It varies :)


Q: Why do the letters have ‘ around them when the numbers don’t?

A1:  Letters, whether it is a string or a character, are a type called strings. Numbers can be integers or strings. If they have quotes (‘ ‘) they are strings. If they don’t have quotes, they are numbers. You can do math with numbers but you cannot do math (like adding etc) with strings


Q: so we can choose what to call the parameter right? It doesn’t have to be a, b

A1:  Absolutely! Just like variables you decide what to call your parameters.


Q: Can’t you just hit the run button on the upper right corner? Like in InteliJ or CLion

A1:  Let’s ask Juliette at the end of lecture!

A2:  mmmm I’m actually not sure. My guess would be that it does not work because you have to indicate which program to run etc.


Q: For the homework that’s due today, can we use like a flag (i=1) or something like that for the alternating bit problem?

A1:  No you cannot use any variables or for loops on the Bit homework.


Q: do you need to be in the specific directory that the file is located in order to run the files?

A1:  Yes, this will all be discussed in the Pycharm handout :)


Q: Should we download it for hw or now?

A1:  You should download Pycharm after class when the handout is released on the class website :)


Q: Is this command line interpreter is part of PyCharm ?

A1:  Yes :)


Q: I think this might’ve been asked before but for this week’s homework, do we use everything we learned up till today or just last week’s lectures?

A1:  No, for the Bit homework you only need lectures 1-3. You cannot use variables or for loops on the Bit homework. Thanks for checking :)


Q: why are we multipying average with 1.0?

A1:  1.0 or now 1.3 is the treshold to check if a pixel is “red enough”.


Q: can you explain the average again?

A1:  live answered


Q: How would we know to multiply the average by the hurdle value?

A1:  The problem description told us to do so. “Detect the red pixels, change them to 10% brightness. Use the average technique which works very well. Adjust the 1.0 factor - hurdle adjustment. A factor of 1.2 looks good.”


Q: why did we multiply by 1.0?

A1:  1.0 or now 1.3 is the treshold to check if a pixel is “red enough”.


Q: why two slashes for division?

A1:  Two slashes // indicates integer division (round down to the nearest whole number). Single slash / indicates float or decimal division (give the exact number resulting from the division).


Q: Can you explain again the *1.3?

A1:  1.0 or now 1.3 is the treshold to check if a pixel is “red enough”.


Q: so it truncates?

A1:  Yep, integer division, //, always rounds down to the nearest whole number.


Q: How we decided that 1.3 factor and how the change in its value impacts our color combination, what is the exact calculation mathematically going in the background, its confusing.

A1:  We are iterating over the pixels in the image and we are comparing the red channel to the average pixel value (red + blue + green) // 3. If the red channel is greater than the average multiplied by some factor (we ultimately decided on 1.3 but we had to play around to emperically pick this factor), i.e. it’s is red enough, we are changing the pixels brightness.


Q: if you pass decimal to rgb colors will it give an error or round it for you?

A1:  If you pass decimals to image.get_pixel(x, y) you will encounter an error


Q: What would happen if you did 1.4? or 1.5? or 1.6?

A1:  The computer would pick up fewer red pixels.


Q: What would happen if you put in 1.7? Would that be better or too far?

A1:  Too far.


Q: Also, why we are using values againt pixel.red 01.

A1:  I’m assuming you’re referencing the pixel.red *= 0.1 etc. When we find a “red enough” pixel, we are instructed to dim the pixel brightness to 10% so we multiple the old values by 0.1


Q: is it up to us to decide when to stop making the factor larger? For example, what if someone thought 1.4 was better?

A1:  Yes, this is a decision that you will make as an indivdual coder


Q: In the tech industry, what’s the advantage of knowing how to do this when photoshop apps can do it for you? Thanks!

A1:  More customization and learning some coding strategies :)


Q: Can we do average * 1.45? or it can only be 1.4?

A1:  You could do average * 1.45


Q: what exactly does the back_pixel = back.get_pixel(x, y) do?

A1:  We are getting the pixel from the back image at a coordinate (x, y).


Q: Can she re-explain why we do the lines pixel.red = back.pixel.red, etc?

A1:  Yes we are setting the pixels in one image to equal the pixels in another image.


Q: are there going to be assignments on pictures

A1:  Yes, you will have image homework :)


Q: just curious, is this process of replacing pixels the same for converting images to png(transparent) form?

A1:  live answered


Q: Will we be downloading PyCharm in our own time?

A1:  Yes, a handout with instructions will be posted on the class website :)


Q: Random thought: I love your necklace, Juliette! Could you share where you got it? Thanks :)

A1:  I got it in Paris last week. I will try to find the name of the store :) Thanks!


Q: Where to find the homework?

A1:  Posted on the class website tomorrow.


Q: Do the images have to be the same size? What would happen if (for example) you wanted to change the background of a picture that is 100x100, but the back image is only 50x50?

A1:  They can be different sizes but then you have to do some math :)


Q: Do zoom backgrounds use a similar program to the bluescreen programs we saw today?

A1:  Yes!


Q: What was the competition. I didn't get it

A1:  You will submit a fun blue screen image and we will pick our favorites :)


Q: how do we download py charm?

A1:  A handout will be released on the class website with instructions :)


Q: When would the competition be due?

A1:  When HW 2 is due :)


Q: When will the image homework be available?

A1:  Tomorrow on the class website :)


Q: Are you still in Paris? I am there as well

A1:  I am back in the United States for the rest of the summer :)


Q: what is the difference between community edition and ultimate edition for Pycharm

A1:  Not sure! Wait to download Pycharm until the instructions are released


Q: After learning Pythin, what language do you reccomend we learn? Most useful/popular

A1:  At Stanford we teach C++ after Python


Q: What's your favorite langauge in CS?

A1:  My favorite language is Python :)


Q: what is the most common language?

A1:  Python is quite popular. Java and C++ are popular as well


Q: What is leet coding

A1:  It’s a website where you can solve common coding problems :) Great for preparing for tech interviews


Q: how different are programming languages?

A1:  Not so different. Once you learn one you can learn others!


Q: What is/are the most similar language(s) to python?

A1:  Python is pretty unique!


Q: What's the most object-oriented programming language? If such a thing exists

A1:  Maybe Java? I am not so sure.


Q: How many coding languages do you both know?

A1:  5 or 6 maybe


Q: Can we integrate python codes to excel via VBA?

A1:  hmm I haven’t tried


Q: For the homework due today, if we are asked to write 2 or more helper functions do we have to use both functions in the main function, or can we nest one in another and then use that in the main function?

A1:  Either works :)


Q: When do we know our grades on the assignment?

A1:  You’ll learn your grade during your IG :)


Q: Does check or check plus indicate full credit?

A1:  Check plus is some sort of A depedning on where you fall in the check plus bucket


Q: How will we set up the one-on-one time with our section leader?

A1:  You’ll sign up for IGs on paperless