*** shmohamud has quit (Ping timeout: 480 seconds) | 04:54 | |
*** fkoikoi has quit (Ping timeout: 480 seconds) | 12:12 | |
shmohamud | good day | 12:49 |
---|---|---|
fkoikoi_ | Good morning shmohamud | 12:51 |
scooper | good morning shmohamud how are you doing in health now??? | 12:51 |
shmohamud | I'm doing much better now, thanks for asking | 12:52 |
shmohamud | so, do you guys have any questions before we kick off today's lesson? | 12:52 |
scooper | For me no | 12:53 |
shmohamud | fkoikoi? | 12:53 |
fkoikoi_ | no | 12:54 |
shmohamud | scooper, can you write me a function that takes in a number and returns me the same number to the power of 2? | 12:54 |
scooper | yes | 12:54 |
shmohamud | fkoikoi, can you write me an example of assigning a value to a variable and then reassigning it to a numeric expression? | 12:54 |
shmohamud | please do scooper | 12:55 |
scooper | should I all it's just a question???? | 12:55 |
shmohamud | nope, please do | 12:55 |
shmohamud | and remember it's important to name the function properly | 12:55 |
scooper | def exponentiation(number): | 12:58 |
scooper | number = number ** number | 12:58 |
scooper | return number | 12:58 |
scooper | print(exponentiation(13)) | 12:58 |
shmohamud | scooper, great job, that works. | 12:59 |
shmohamud | My one recommendation is to use verbs when you're naming functions | 12:59 |
scooper | OK shmohamud | 12:59 |
shmohamud | if you're raising to a power, something like raise_to_power | 12:59 |
shmohamud | but the name is better than previous, so great job on imrpoving | 13:00 |
scooper | I will that and put it in to practice when learning | 13:00 |
shmohamud | fkoifkoi are you there? | 13:00 |
shmohamud | Scooper, are you familiar with the different comparison operators? | 13:00 |
scooper | yes | 13:00 |
shmohamud | can you name 3 now? | 13:00 |
scooper | yes | 13:00 |
shmohamud | please do | 13:01 |
scooper | !=, >=, <=, ==, | 13:01 |
shmohamud | beautiful | 13:01 |
fkoikoi_ | school = "only student are allow" | 13:01 |
fkoikoi_ | number = 46 | 13:01 |
shmohamud | ok, fkoikoi good attempt. The key word is "reassign" that means taking the variable school and assigning it to 46 | 13:03 |
shmohamud | And when I say numeric experssion, I mean a chunk of code that executes first using numbers, like 46 + 9 | 13:03 |
fkoikoi_ | okay | 13:04 |
shmohamud | spencer, do you know how indentation works in Python? For conditionals and loops | 13:04 |
scooper | yes | 13:04 |
fkoikoi_ | school = "only student are allow" | 13:05 |
fkoikoi_ | school = 46 * 6 | 13:05 |
scooper | The are two ways to indent in python, you either press the space back key on the key four time after use the tab key one time | 13:06 |
shmohamud | nice | 13:06 |
scooper | But this should be done under the condition or loop | 13:06 |
shmohamud | ok, what do we call a function that has no return value in Python? | 13:06 |
scooper | null | 13:07 |
shmohamud | void functions, or "not fruitful" functions | 13:07 |
shmohamud | null is close enough, in my opinion | 13:08 |
scooper | sorry void | 13:08 |
scooper | mean empty | 13:08 |
shmohamud | yes | 13:08 |
shmohamud | do you guys know how to break out of a loop in python? | 13:08 |
scooper | yes | 13:09 |
fkoikoi_ | no | 13:09 |
shmohamud | spencer, can you write a for loop that prints every number from 1 to 100 but has a conditional that if the number is greater than 20, break | 13:10 |
shmohamud | ? | 13:10 |
scooper | let me give it a try | 13:10 |
shmohamud | this way, we can demonstrate for fkoikoi how break statements work in Python | 13:11 |
shmohamud | fkoikoi, are you familiar with indexing strings in Python? | 13:15 |
scooper | def countingNumber(checkingValue): | 13:17 |
scooper | for value in range(100): | 13:17 |
scooper | if value > 20: | 13:17 |
scooper | break | 13:17 |
scooper | return value | 13:17 |
scooper | print(countingNumber(value)) | 13:17 |
fkoikoi_ | no | 13:17 |
scooper | please wait I m still figuring out what when run | 13:17 |
shmohamud | spencer, did I ask to return the value or print every number leading up to the break? | 13:18 |
shmohamud | ok fkoikoi, we'll jump into indexing right after this :) | 13:18 |
scooper | you said print the value | 13:19 |
scooper | so when the function is called out of the function body | 13:19 |
scooper | I m expecting it to print the value | 13:19 |
shmohamud | yes, print every number from 1 to 100 leading up to the break, including the 20 but not 21 | 13:20 |
shmohamud | ok, give it another shot and we'll work together if it's not perfect | 13:21 |
shmohamud | fkoikoi, check out the powerpoint slides here on indexing strings in the meantime: https://www.py4e.com/lessons/strings | 13:25 |
scooper | number1 = 0 | 13:26 |
scooper | number2 = 100 | 13:26 |
scooper | def countingNumber(number1, number): | 13:26 |
scooper | for value in range(number, number2): | 13:26 |
scooper | if value == 20: | 13:26 |
scooper | break | 13:26 |
scooper | print (value) | 13:26 |
scooper | print(countingNumber(number1, number2)) | 13:26 |
scooper | still not working | 13:26 |
scooper | number1 = 0 | 13:27 |
scooper | number2 = 100 | 13:27 |
scooper | def countingNumber(number1, number2): | 13:27 |
scooper | for value in range(number1, number2): | 13:27 |
scooper | if value == 20: | 13:27 |
scooper | break | 13:27 |
scooper | print (value) | 13:27 |
shmohamud | ok, you've got a good start here. First, remove number1, number2 arguments from the function, we don't need to call this function with arguments since we know we want to loop high | 13:27 |
scooper | print(countingNumber(number1, number2)) | 13:27 |
scooper | I just did | 13:27 |
shmohamud | second, in range(100) just print the number on the next line instead of after the break and inside the conditional. If we have the print statement after the break, it will never run, because the break takes us out of the loop! | 13:28 |
shmohamud | so, if you move print(value) to be right under the for loop, this should work fine | 13:28 |
shmohamud | But also notice, when you're calling a function with arguments, you can't provide undefined variables. print(countingNumber(number1, number2)) doesn't know what number1, number2 are because they're undefined | 13:29 |
shmohamud | Finally, do you need a print statement when calling this function? | 13:30 |
shmohamud | as you did with print(countingNumber(number1, number2))? | 13:30 |
scooper | TypeError: countingNumber() missing 1 required positional argument: 'number2' | 13:32 |
shmohamud | why don't you remove number1, number2 from the entire function, and go back to using range(100) ? | 13:32 |
scooper | If I removed the argument this is what will happen shmohamed | 13:32 |
shmohamud | let's see the code please | 13:33 |
shmohamud | fkoikoi are you paying attention? :) | 13:33 |
scooper | def countingNumber(number): | 13:34 |
scooper | for value in range(100): | 13:34 |
scooper | print(value) | 13:34 |
scooper | break | 13:34 |
scooper | 13:34 | |
scooper | print(countingNumber(100)) | 13:34 |
shmohamud | ok, so first off, why don't you remove the number argument from the function and also from where you're calling it? | 13:35 |
scooper | If I removed the "break" the code will run from 0 t0 99 | 13:35 |
shmohamud | this is a good start, but let's do some cleanup, ok? | 13:35 |
scooper | TypeError: countingNumber() missing 1 required positional argument: 'number' | 13:36 |
scooper | if I removed the argument that will be the error | 13:36 |
shmohamud | because you have to remove it from the function definition too, have you done that? | 13:37 |
scooper | that mean I write a void function right??? | 13:37 |
shmohamud | not necessarily | 13:37 |
scooper | A will output 0 and NONE | 13:37 |
shmohamud | but remember this is just a teaching example for the break statement | 13:38 |
shmohamud | it will still print numbers up to 20, right? | 13:38 |
scooper | if I removed the parameter | 13:38 |
scooper | def countingNumber(): | 13:38 |
scooper | for value in range(100): | 13:38 |
scooper | print(value) | 13:38 |
scooper | break | 13:38 |
scooper | 13:38 | |
scooper | print(countingNumber()) | 13:38 |
scooper | that is the code snippet | 13:38 |
shmohamud | so does this print 1 | 13:38 |
scooper | No | 13:39 |
scooper | zero and NONE | 13:39 |
shmohamud | what happens? | 13:39 |
shmohamud | oh wait a minute | 13:39 |
shmohamud | why do you call print(countingNumber()) | 13:39 |
shmohamud | ? | 13:39 |
shmohamud | shouldn't we just call countingNumber() | 13:39 |
shmohamud | fkokoi, I'm sorry to hear about the headache and stress. Take it easy today, we will have many more sessions. Pay attention where possible, no pressure. | 13:40 |
scooper | I DID | 13:40 |
scooper | It print 0 | 13:40 |
shmohamud | scooper, we're almost there! | 13:40 |
shmohamud | So, what's left to make it work as I asked? | 13:41 |
scooper | to set a conditional statement | 13:41 |
scooper | right??? | 13:41 |
shmohamud | yes, and have it break when it hits 21 | 13:42 |
shmohamud | so we should see numbers from 0 to 20 printed | 13:42 |
scooper | Today is challenging | 13:45 |
scooper | def countingNumber(): | 13:45 |
scooper | for value in range(100): | 13:45 |
scooper | print(value) | 13:45 |
scooper | break | 13:45 |
scooper | if value >= 20: | 13:45 |
scooper | print(value) | 13:45 |
scooper | 13:45 | |
scooper | (countingNumber()) | 13:45 |
scooper | Please hold on | 13:45 |
shmohamud | ok | 13:45 |
scooper | I need to indent the if statement under the for loop | 13:46 |
shmohamud | you're doing a great job, by the way. | 13:46 |
shmohamud | ok | 13:46 |
shmohamud | make the indent properly | 13:46 |
shmohamud | then, ask yourself, where should the break statement go? | 13:46 |
scooper | I got it | 13:47 |
scooper | def countingNumber(): | 13:47 |
scooper | for value in range(100): | 13:47 |
scooper | print(value) | 13:47 |
scooper | if value >= 20: | 13:47 |
scooper | break | 13:47 |
scooper | print(value) | 13:47 |
scooper | 13:47 | |
scooper | (countingNumber()) | 13:48 |
shmohamud | well done. have you run the code? | 13:48 |
scooper | +1 | 13:48 |
shmohamud | ok, two comments | 13:48 |
scooper | I need to see the previous code to know all of my errors | 13:49 |
shmohamud | first, can you re-write the conditional so it includes 20? | 13:49 |
shmohamud | I want 20 to be printed out, but not 21 | 13:49 |
scooper | 20 is already included | 13:49 |
shmohamud | so that 20 gets printed out | 13:49 |
scooper | yes | 13:49 |
scooper | Please run the code again | 13:49 |
shmohamud | it's getting printed out already? | 13:49 |
shmohamud | Ok, second comment: do we need the print(value) after the break? | 13:51 |
scooper | yes for beginner level | 13:52 |
shmohamud | what do you mean for beginner level? | 13:52 |
scooper | I mean beginner like me need to do so for now | 13:52 |
shmohamud | hahahaha | 13:52 |
shmohamud | I see. Well, you're doing great, I'm impressed and excited to work with you to make you an expert level. | 13:53 |
scooper | Am I right for now??? | 13:53 |
scooper | Thanks shmohamud | 13:53 |
shmohamud | Yes, you're right. But one more question, do you need to define a function to do this? | 13:53 |
scooper | You mean the program we just wrote??? | 13:54 |
shmohamud | yes | 13:54 |
shmohamud | spencer, can you write a for loop that prints every number from 1 to 100 but has a conditional that if the number is greater than 20, break | 13:54 |
shmohamud | the question ^^ | 13:55 |
scooper | I will say yes, if we will like to use this program in another place... that is why function is so important | 13:55 |
shmohamud | Bingo, good answer! | 13:56 |
shmohamud | Ok, so I have an appointment in 4 minutes. Any last questions before I get going for the day? | 13:56 |
scooper | But if we want this to be a global variable that other program can use them we can defined it outside the function | 13:57 |
shmohamud | can you define a function as a variable? They're two different animals right? | 13:57 |
scooper | No | 13:58 |
shmohamud | ok | 13:58 |
scooper | it is not advisable to do that according to Python for everybody | 13:58 |
shmohamud | good | 13:58 |
shmohamud | ok, any final questions? | 13:58 |
scooper | yes | 13:59 |
scooper | Why do function variable have the same names in seporate function but don't render error or encounter conflict??? | 14:00 |
scooper | example | 14:01 |
shmohamud | ok scooper can you wait 1 hour for me to finish my appointmenrt? | 14:01 |
scooper | OK let meet tomorrow | 14:01 |
scooper | please shmohamud | 14:01 |
scooper | All we should stick around?? | 14:01 |
*** fkoikoi_ has quit (Quit: Leaving) | 14:08 | |
shmohamud | hi scooper | 14:51 |
shmohamud | are you still here? | 14:51 |
scooper | yes | 14:51 |
scooper | I m here | 14:51 |
shmohamud | sorry for not replying earlier. | 14:51 |
shmohamud | The appointment was for 10AM | 14:51 |
scooper | I understand | 14:52 |
shmohamud | Why do function variable have the same names in seporate function but don't render error or encounter conflict??? | 14:52 |
shmohamud | is that your question? | 14:52 |
scooper | yes | 14:52 |
scooper | Programmer | 14:52 |
shmohamud | lol ok, let's see. | 14:52 |
scooper | should I put an example ??? | 14:53 |
shmohamud | so, you're wondering why we could have two or more functions that use the same variables inside of them, but there's not an error? | 14:53 |
scooper | yes | 14:53 |
shmohamud | e.g. def get_info: | 14:53 |
shmohamud | info = "Test info" | 14:54 |
shmohamud | def delete_info: | 14:54 |
shmohamud | info = "Test info" | 14:54 |
shmohamud | like that? | 14:54 |
shmohamud | both functions have info variable defined? | 14:54 |
scooper | Are the info serving as inter variable right?? | 14:54 |
scooper | in the two function?? | 14:55 |
scooper | If yes, that is exact what I mean | 14:55 |
shmohamud | info is inside the functions, so it's two different variables even though they have the same name. This is because of what's called "scope" | 14:55 |
scooper | *exactly | 14:55 |
shmohamud | Let me find a good resource for you | 14:55 |
shmohamud | https://realpython.com/python-namespaces-scope/#variable-scope | 14:56 |
shmohamud | the reason is because the variables are local scope | 14:57 |
scooper | global or local?? | 14:58 |
shmohamud | local | 14:59 |
scooper | ok | 14:59 |
shmohamud | ok scooper | 15:02 |
shmohamud | anything else? | 15:02 |
scooper | No Shmohamud | 15:02 |
shmohamud | alrighty, see you tomorrow. Great job toeday. | 15:02 |
scooper | Thanks Shmohamud | 15:02 |
shmohamud | you're welcome4 | 15:03 |
shmohamud | have a great rest of the day | 15:03 |
scooper | ANy | 15:03 |
scooper | message from Jeff | 15:03 |
shmohamud | nope, he's busy this week | 15:04 |
scooper | All right??? | 15:05 |
shmohamud | all is well with Jeff | 15:05 |
shmohamud | spoke to him Monday | 15:05 |
scooper | Do you stay in Arlington too??? | 15:07 |
scooper | Can I leave now shmohamud??? | 15:08 |
*** scooper has quit (Quit: Leaving) | 15:09 | |
*** shmohamud has quit (Remote host closed the connection) | 15:09 | |
*** shmohamud has quit (Remote host closed the connection) | 15:20 | |
*** shmohamud has quit (Remote host closed the connection) | 17:48 | |
*** shmohamud has quit (Remote host closed the connection) | 17:55 | |
*** scooper has quit (Quit: Leaving) | 17:57 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 18:04 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 18:15 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 18:36 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 18:45 |
Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!