Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

This page removed for FERPA compliance
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Spring 2003: What does it mean?

Try the problem here from Sp 2003 Midterm Review #1



Def means that you are about to assign code to some data; it is the beginning of a function. ?someREMOVEDnction? is the name of the function that is about to be defined and x and y are the inputs.

?for? tells the code which variable and/or entity are you are about to change

Print tells JES to display to the user the value of a suggested piece of information. It displays the actual numbers and/or values that are associated with an entity or the operation that the user commanded (ie ?print 1+2 would display ?3? as an answer. ?print a? would display ?a?

Actually, if you test the last suggestion here, you won't have "a" printed on the screen. In order to print something on the screen in JES, you must use quotes around it. So to print the first letter of the alphabet one would type: print "a"
If you don't type the quotes around it you get: A local or global name could not be found.
I'm guessing this happens because the computer doesn't understand what 'a' does. The computer thinks that it's some form of command. For example, when you tell the computer to "print file", it associates "file" as the command name for whatever you defined it as. If I assigned "file" to pickAFile() and picked a "file", the computer would assume that "file" was the command word associated with the file I picked. It would, therefore, print the filename on the screen.
Rebecca


Various responses:

Mark Guzdial



def means only that you are naming the action that you're about to teach JES how to do. Def is like telling JES "this is what I'm going to call the function I'm about to give you." Whatever follows the "someREMOVEDnction" part in the parentheses is telling JES what to take as input. So the statement "def someREMOVEDnction(x,y):" literally just names your function in JES and tells it that it can expect a command (someREMOVEDnction) and two variables (x,y) when you want to run that function.
Lauren
Very nice – does someREMOVEDnction require "variables" as input? Or can it be values, like someREMOVEDnction(1,2)? Mark Guzdial


For is a keyword that tells JES that something is a loop - that it's going to have to do something over and over again. The "for" loop does some command that you tell it to for an array that you provide (this is almost directly from the textbook p.64), where each time that the commands are executed, a particular variable (that you have named) will have the value of a different element of the array. For example "for p in getPixels(picture)" means that whatever is to follow (the loop) will be applied to all of the pixels in the named picture. The statement "for x in range(1,5)" means that each x value between 1 and 5 will have the following action(s) performed to it.
Lauren

print is a command that tells JES just to show on the screen whatever has been assigned to a certain variable (or name). For example, "print file" when you have selected a file will name the pathway. "print "b" " makes it write the letter b. "print a" will only generate something if you have given "a" a value somewhere else.
Lauren
Whatever comes after print will be evaluated – literally, Python will look for a value for what follows. print a will seek a value for a. Mark Guzdial


When I said "file" as a command word, I meant, in my terminology, that it is the value assigned to "file". In my example, I referred to picking a file and assigning it the name "file" or value of "file". Python looks for what I assigned "file" to- in this case, some filename that I selected through pickAFile(). Python evaluates it and displays it (the path/string for the filename) on the screen. I hope that's a REMOVED clearer or better understanding of what I was attempting to explain.
Student116


"for" assigns a variable to some data and tells the computer to continue looping through doing whatever you assigned after it. In the example: "x" is the variable; "range(1,5)" tells you to start at 1 and when you cycle through, do it 4times; the "for" tells it to cycle through and perform whatever function you created after the the "for" loop.
"print a" tells the computer to display on the screen the contents of "a" (whatever you assigned to "a").
Student116

"for" actually walks a variable through a SEQUENCE. range(1,5) generates a sequence of [1,2,3,4]. getPixels(picture) generates a sequence of every pixel in the picture. getSamples(sound) generates a sequence of every sample in the sound. The "for" statement just makes the variable take each value in the sequence, one at a time, then execute the for's block. Mark Guzdial


When the line print a is typed in, it looks to the instance variable a to see if there is a variable assigned to that value. Since there arent any "" around the a, it doesnt just print the letter. If the variable a has been used, it prints out that variable's location in memory.



Link to this Page