[02:43] exit [14:54] Hi DiegoTc [14:55] hi ibuclaw [14:57] DiegoTc, what will you be covering? [14:58] ibuclaw, the basic of c++(cout,cin, the if and else, the switch) [15:00] STL... [15:01] yucky... :-) [15:03] ibuclaw, whats STL? [15:04] C++ Standard Template Library === emma is now known as mc44 === mc44 is now known as emma === saji89 is now known as opensorcerer [15:58] hey DiegoTc [15:58] hi Bodsda [16:01] okay it is time [16:01] w00t === ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - https://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Questions in #ubuntu-classroom-chat || Event: Beginners Team Dev Academy - Current Session: C++ for Beginners - Instructors: DiegoTc [16:02] hi guys [16:02] I am going to start with the C++ for Beginners [16:02] if you had any question just let me know [16:03] and i will try to answer it :) [16:03] okay so lets see, did everyone install the build-essential? [16:03] and the codeblocks? [16:04] okay, if you haven't installed codeblocks we can use gedit for writting our code [16:05] opensorcerer, codeblocks it is not necessary [16:05] i recommend because its a great IDE for beginning on c++ [16:06] if you are going to use codeblocks create a new file [16:06] and lets save it with the name of helloworld.cpp [16:07] if you are going to use gedit, les open also a new file and save it with the same name helloworld.cpp [16:07] did everyone did this? [16:08] okay [16:08] so know we are going to type this [16:09] #include [16:09] I will explain what the iostream means [16:09] Carroarmato0, yes [16:10] for c++ the comments consist this way [16:10] / [16:10] / [16:10] "//" [16:10] with out the "" [16:10] okay http://paste.ubuntu.com/500372/ [16:11] thats the code of the hello world [16:11] copy it or type it :) [16:11] and in some seconds we will compile it and i will explain it [16:12] !q [16:13] !question [16:13] I am having a little trouble with the ClassBot so lets answer this questions [16:14] QUESTION: why we need "using namespace std;" [16:15] Mohan_chml asked: why we need "using namespace std;" [16:15] namespace definition=is an abstract container providing context for the items (names, or technical terms, or words) it holds and allowing disambiguation of homonym items residing in different namespaces. [16:16] in normal words iostream is the library that contains many functions so I am using the using namespace std; [16:16] to include them all [16:16] but we can especify which ones to use [16:17] pedro3005 asked: Shouldn't we "return 0;" at the end of the program? [16:17] yes and no [16:17] if you are using it on windows you have to do it, on linux no [16:19] i think i amswer all of your question right now? opensorcerer in some min i will answer yours [16:20] everyone copy this code? http://paste.ubuntu.com/500372/ [16:20] lets continue [16:21] if we are using codeblocks [16:21] lets save the file [16:21] in gedit also [16:21] so the codeblock users lets go to the Build menu [16:22] lets click on the BUILD option [16:22] and on the down part we are going to see the message that process end it with 0 errors [16:23] if you are using gedit [16:23] lets open the terminal [16:23] lets go to the directory where you save the file [16:23] lets suppose you are save it on home [16:23] so do a cd /home [16:24] and you are going to do this [16:25] g++ -o helloworld helloworld.cpp [16:26] ready? [16:26] for everyone this is important [16:26] the g++ is the compiler [16:26] -o indicates the name of the executable [16:27] which will be helloworld [16:27] and for last the name of the cpp file [16:27] so if you are in the terminal [16:27] for executting the program just do this [16:28] ./helloworld [16:28] in codeblocks go to to BUILD [16:28] and click on run [16:28] and a small terminal will appear with [16:28] Hello World [16:29] did everyone got the hello world? [16:30] Okay guys [16:30] give 1 min [16:31] okay lets continue [16:32] each time you begin to program on c++ [16:32] you have to have the main(){CODE} [16:33] the cout<< it is for showing the message [16:33] it is equivalent to the print of python or c [16:34] each time you are going to print a string you must include "" [16:34] and here each end of line ends in ; [16:34] did everyone got that [16:34] now [16:34] if we want to read from the keyboard [16:35] we have to use cin>> [16:35] c++ has different types of variables [16:36] for numbers = int, double, float [16:36] char [16:36] bool [16:36] string [16:36] so lets make this small exercise [16:38] fibolinux, yuo have to use "\n" [16:40] okay copy this example http://paste.ubuntu.com/500395/ [16:41] let me know when you have it [16:42] okay if you copy it build it and run it :) [16:43] did everyone got it? [16:44] okay i suppose that is a yes [16:44] with c++ [16:44] you can use it for math operations [16:44] examples [16:44] 5+5=10 [16:46] we declare a variable int ans [16:46] ans=5+5; [16:46] and that will give us 10 [16:46] opensorcerer asked: How do i use \n while printing num ? [16:47] opensorcerer, could you be a little more specific [16:47] i don't get you [16:48] okay opensorcerer [16:48] easy [16:49] cout<<"The number is: "< opensorcerer, i thinks you referred to that [16:50] i forgot this detail [16:50] on the cout you can print everything in the same line [16:50] using << [16:51] on the last example we did this [16:51] cout<<"The number is: "; [16:51] cout<< number; [16:51] but we can do it his way also [16:51] cout<<"The number is: "< so know that we know some basic concepts lets make another exercise together [16:52] lets make a small program that the user enters 2 numbers [16:52] and we have show the sum of this 2 numbers [16:53] so lets begins what w have to do first¿? [16:54] if anyone ones to do it alone write and if it works copy it on http://paste.ubuntu.com this way everyone could see it [16:55] okay first of all we need to write this [16:55] #include [16:55] using namespace std; [16:55] main() [16:55] { [16:56] wehave to declare 3 variables of (int) type [16:56] it could be double or floats if we are going to add decimals [16:57] Carroarmato0, very good [16:57] http://paste.ubuntu.com/500403/ [16:58] he declare his 2 variables [16:58] int var1, var2; [16:58] he use the cout for telling the user what the program wants [16:58] cout << "Give me 1st number: "; [16:59] the cin for reading the number [16:59] cin >> var1; [16:59] and in the same cout he gave the answer cout << "The sum is: " << var1 + var2; [17:00] there are many ways of doing it [17:00] http://paste.ubuntu.com/500411/ [17:00] in this one i declared a third variable for giving the answer [17:01] pedro3005 asked: how do we convert between types? === ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - https://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Questions in #ubuntu-classroom-chat || [17:01] pedro you are referring how to convert an int to a string= [17:01] DiegoTc, and float to int, etc [17:02] pedro3005, you have to make typecasting [17:02] http://www.cplusplus.com/doc/tutorial/typecasting/ [17:03] thanks for the lesson DiegoTc [17:03] i have problem on C language ! [17:03] bihari_, what is it? [17:03] np pedro3005 [17:04] write a programme to print greatest and smallest number inside 1d array [17:04] use codepad.org [17:05] pedro3005, write a programme to print greatest and smallest number inside 1d array [17:07] bihari_, well, do it like this: declare a variable called max_num, and set it to 0. Iterate over the array and compare max_num to the elements. If they are greater, put that in max_num and continue. by the end, you'll have the greatest number in max_num. [17:08] then just print max_num, obviously [17:11] humm can you wright that code? [17:11] sorry, not going to do homework for you [17:12] bihari_: Otherwise just sort the numbers in the array and take the largest and smallest, since you need both. [17:12] oh yeah, he needs the smallest too [17:12] opensorcerer, but as C has no standard function to sort an array, that might be too much work [17:13] just have two vars, max_num and min_num [17:13] pedro3005: He can use the usual nested loop sorting technique. Its really easy. :) [17:13] yes [17:13] opensorcerer, you mean bubble sort? [17:14] it will be short out in the nested loop [17:14] yes what is buuble sort [17:14] ? [17:14] pedro3005: I guess so. [17:14] i wants to know [17:14] http://en.wikipedia.org/wiki/Bubble_sort [17:15] bihari_: http://en.wikipedia.org/wiki/Bubble_sort [17:15] opensorcerer, yeah, but that algorithm spends a great amount of computational steps which are simply not needed. [17:15] pedro3005: :) [17:15] pedro3005: Ok. [17:15] I'd rather expend the memory to store two ints than sort an array, specially through an inefficient algorithm [17:15] just my opinion [17:16] pedro3005: I go with your opinion, it seems more efficient. :) [17:17] opensorcerer, since we're talking about C here, both will be so fast that the difference is not notable. But let's stick to theory :P [17:17] pedro3005: Yes, for the sake of larger programs that he/we may do in future. :) [17:17] if it was python, though [17:18] pedro3005: So now we have to variables max_num and min_num. How exactly will we porceed? [17:18] proceed* [17:18] pedro3005: You have inbuilt sorting methods in python. right? [17:18] opensorcerer, well, i'll write some pseudo-code (so we avoid ctrl + c methods :D) [17:18] pedro3005: we compare once to get max_num and then again to get the min_num? [17:19] opensorcerer, yeah, hold on [17:21] pedro3005: Sure. I'm also trying it. :) [17:21] opensorcerer, with python, we have two standard functions: max() and min() [17:21] :) [17:23] pedro3005: Python is super-awesome. :) [17:24] opensorcerer, this pseudo-code would work http://paste.pocoo.org/show/267209/ [17:26] pedro3005: See my pm. [17:26] pedro3005: you are awesome [17:27] bostikforever, ..thank you [17:27] Do you use Netbeans? [17:27] nope, too slow [17:27] Geany [17:28] Okay [17:28] I'm having some link ish's with my Netbeans [17:28] could you be of any help? === JoeMaverickSett is now known as Guest74138 === JoeMaver1ckSett is now known as JoeMaverickSett === opensorcerer is now known as Guest90146 === Guest90146 is now known as saji89 [17:51] bihari_: how's is your program going? [17:52] saji89, its going good [17:52] how about you saji89 what you doing? [17:53] bihari_: I'm fine. Just gonna attend the Pythin session here. Let's move to #ubuntu-classroom-chat, since the session will be starting here now. :) [17:53] ok === ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - https://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Questions in #ubuntu-classroom-chat || Event: Beginners Team Dev Academy - Current Session: Introduction to Python: Part 2 - Instructors: pedro3005 [18:01] Alright [18:02] First, I'd like to say that now we can properly use the question system, since the stupid pedro3005 finally learned how to use the bot. [18:02] Well, it was quite complex. I mean, three commands?!? not something you grasp over an afternoon [18:02] But let us go on [18:03] We'll begin with a revision of what we saw last class [18:03] We learned what is the python shell and we learned it can evaluate commands [18:04] That is great for testing purposes, but at some time you must be able to create a file with your program in it [18:04] So that's what we're going to do now [18:05] First, open your favorite editor [18:06] albel12051 asked: do this has the slides [18:06] No. the instructor is too lazy (damn that guy, huh) [18:07] Well, in your editor, let's begin with the old classic we also learned last class [18:07] print "Hello, world!" [18:07] After you write that, save your file as hello.py [18:07] You can now execute your file by running the command 'python hello.py' [18:08] Now, we can notice some important distinctions in python [18:08] for instance [18:08] Go to your file and write: [18:08] print 1+1 [18:08] now run that file with the above method and you'll see it outputs 2 [18:09] Go back to the file and change that to simply [18:09] 1+1 [18:09] Now run it. You will notice nothing happens [18:09] The expression was evaluated, but since there was nothing to do with it, it was thrown away [18:11] Guys [18:11] I am TERRIBLY sorry. I need to get away for 5 little minutes. I'll be right back after that to continue the session. Really sorry, this is just a thing I could not have foreseen [18:11] hope you will excuse me [18:12] I'll be back as soon as I can, should take just some minutes === guest_ is now known as Scio === Scio is now known as Guest64706 === fred_ is now known as Guest24596 [18:20] I AM BACK [18:20] well, it took 8 minutes. I'm not the fastest runner [18:20] sorry [18:21] ok [18:21] where were I [18:21] Oh yeah, files [18:21] So as I was saying, if you don't tell python to do something with the expression, it is thrown away [18:21] We also learned about variables, their types and how to declare them [18:22] you can for instance declare an int variable x that is 2 [18:22] x = 2 [18:22] Consider this case: you want to raise x's value by one [18:22] Python does NOT have ++ like other languages [18:22] in your file, you could try [18:22] x + 1 [18:22] but we all know that won't work [18:22] it'll be evaluated then thrown away [18:23] we must do [18:23] x = x + 1 [18:23] But wait! [18:23] There is a short way to say that [18:23] we can say that: [18:23] x += 1 [18:23] that is the exact same thing as x = x + 1 [18:24] You can also do it with other signs [18:24] like [18:24] x -= 1 [18:24] or x *= 2 [18:24] and, of course, x /= 2 [18:25] saji89 asked: When we put it in a file don't we put the shebang line at the top? [18:25] Yeah, I'm sorry. I always forget that line [18:25] Start your files with: [18:26] #!/usr/bin/env python [18:26] with this method, you don't need the python [18:26] just make the file executable [18:26] and then do ./file.py [18:27] saji89 asked: IS #!/bin/python [18:27] I haven't seen such a thing, so I don't know. Presumably it is [18:27] But, as we were learning about python's arithmetic system, I forgot one operator [18:28] that's the mod operator, or % [18:28] it is similar to other languages [18:28] it gives you the rest of the division [18:28] for instance, 10 % 3 = 1 [18:29] it divides 10 by 3, and what is left is 1 [18:29] What's the usability of this? A common one is checking whether the number is even or odd [18:29] if the mod of a number by two is greater than zero, this number is odd [18:30] And if % is mod, how do we get percentage? [18:30] Well, that's easy [18:30] if you want 80 percent of a variable, just do: [18:30] 80/100 * x [18:31] or 0,8 * x [18:31] that's basic math [18:31] Any questions? [18:31] DiegoTc asked: why by x? [18:31] Well, x is just an example [18:32] saji89 asked: 0,8 * x means? [18:32] wait [18:32] I'm wrong [18:32] sorry all [18:32] that's [18:32] 0.8 * x [18:32] HoellP asked: is there an operator for root? [18:33] Yes, there is [18:33] you need to import the module math [18:33] import math [18:33] then you can do [18:33] math.sqrt(9) [18:33] for instance [18:33] The math module has many other functions such as sine etc. [18:33] you can learn about them here http://docs.python.org/library/math.html [18:34] Questions? [18:34] Alright, let's move on [18:34] We learned about ifs last class [18:35] We can get an answer from python to boolean expressions, as we saw [18:35] and if directs our program flow given these answers [18:35] for instance, if we have a variable x [18:35] and we want to see if it's positive or negative [18:35] if x > 0: [18:35] print "It is positive" [18:36] else: [18:36] print "It is negative OR equal to zero" [18:36] Well, what if I want to know exactly? We have the keyword elif [18:36] that means "else if" [18:36] so we can rewrite our program using that [18:36] if x > 0: [18:37] print "It is positive" [18:37] elif x == 0: [18:37] print "It is zero" [18:37] else: [18:37] print "It is negative" [18:37] Questions? [18:38] Lastly, we learned about the raw_input() command [18:38] that's what we use to get input from the user [18:38] its return type is a string [18:39] we can say [18:39] answer = raw_input("What is your name? ") [18:40] Well, what if we want to get a number from it? [18:40] age = raw_input("What is your age? ") [18:40] yes, but that's still type string [18:40] we can't do age + 1, because age is a string [18:41] We need to use type conversion [18:41] we can do: [18:41] int(age) [18:41] but that is insecure [18:41] what if the user (never doubt the sheer stupidity of a user) decides to enter "bananas" when asked for his age? [18:41] int("bananas") will make your program crash [18:42] So, we have a method for strings [18:42] HoellP asked: how do i combine variables and text in a print statement? [18:42] You have some options [18:42] you can do [18:43] print "the variable is:" + x [18:43] You can also do [18:43] print "the variable is %s" % x [18:43] The latter seems harder, but if you need a specific formatting that is your option [18:44] saji89 asked: IF we need to print two/more variables in one print statement. [18:44] well, you can do [18:44] print "var one is %s, var two is %s" % (var_one, var_two) [18:45] the thing in parenthesis is called a tuple [18:45] we'll be learning about them later [18:45] But back to our bananas problem [18:45] strings have a method called isdigit() [18:45] you can call it by "any string".isdigit() [18:45] that will return True or False [18:45] in our case, we can simply do [18:46] age = raw_input("What is your age? ") [18:46] if age.isdigit(): [18:46] print "Your %s years old!" % age [18:46] else: [18:46] print "Get off the computer and go back to your crib, kid" [18:47] there are many more methods like this one [18:47] you can learn about them at http://docs.python.org/library/stdtypes.html#str.isalnum (go scrolling down for more) [18:48] Excuse my horrible english [18:48] it is "you're" [18:48] thank you saji89 [18:49] also, that line lacked one space for indentation [18:50] Otto48 asked: is there a function to validate a string as a float number? [18:50] Otto48 asked: or a negative? [18:50] There are ways of doing that, but not with (standard) functions [18:51] What you would need is a try statement [18:51] If you could store that question for a later class [18:51] I really didn't want to go over try with you guys before some things [18:51] Thanks for the comprehension [18:52] but you may notice that int("-4") works just fine :) [18:52] and so does float("4.5") [18:52] newboon2age asked: QUESTION: Were is the log for this session? [18:52] nhandler usually takes care of the logs [18:54] So, basically that is what we learned last class [18:54] I wanted to go over it again to really get it complete [18:54] Let's learn a couple things about ifs [18:55] What if we have to check several expressions? [18:55] we have things like not, and, or [18:55] for instance [18:55] say we have an int x [18:55] if x < 0 and x != 0: [18:55] print "x is negative" [18:56] and another example [18:57] if x < 0 or x > 0: [18:57] print "x is not zero" [18:57] of course, it'd be better to just do [18:57] if x != 0 [18:57] but I couldn't think of a better example :) [18:58] Otto48 asked: Is shortcut evaluation used or are both sides evaluated regardless of the result of one side of the expression? [18:58] Shortcuts are used. if the first expression fails, the other is not checked (if we're dealing with ands, of course) [18:59] We also have not, as I mentioned [19:00] if x > 1 and not x > 10: [19:00] which is equivalent to x < 10, of course (my examples always suck) [19:00] but not _is_ useful sometimes [19:00] Questions? [19:01] Otto48 asked: is 1 It is not [19:01] unfortunately, for the math-inclined, you'll have to do x > 1 and x < 10 [19:03] Let me introduce you guys to a new type now [19:04] In python, we have lists [19:04] If you are familiar with C and other languages, they're like arrays [19:04] but only MUCH better [19:04] A list is a set of elements [19:05] You can define them with the following syntax: [19:05] numbers = [1, 2, 3, 4, 5] [19:06] To get the nth element of a list, we do list[n-1]. That's because the first element is 0 [19:06] in this case [19:06] numbers[0] == 1 [19:06] and so forth [19:06] Questions? [19:07] Ok [19:07] To get the total number of elements in a list you can use the function len() [19:07] len(numbers) == 5 [19:07] Lists are a mutable type, meaning you can add and remove elements from it [19:08] you can use the method append() to add something to a list at the rightmost position [19:08] numbers.append(6) [19:08] now we have numbers = [1, 2, 3, 4, 5, 6] [19:09] saji89 asked: can we make a list immutable? [19:09] Tuples are sort of like immutable lists [19:09] so if you want something immutable go ahead and use a tuple (I'll go over them shortly) [19:10] We also have the remove() method for lists [19:10] numbers.remove(6) will remove the first instance of 6 it finds [19:11] if we had, for instance, num = [6, 6, 6] and did num.remove(6), we'd end up with [6, 6] [19:12] But what if I had [1, 2, 3, 1, 4] and I wanted to remove exactly the last 1? [19:12] well, that is the 3rd element (remember, the first one is 0) [19:12] so we can do [19:12] del numbers[3] [19:13] Or, we can use the pop() method [19:13] list.pop(i) will remove the ith element and return it [19:14] pop(), without arguments, defaults to the last element [19:14] Any questions about that? [19:16] Otto48 asked: Is there a push method too? [19:16] yes, the method append() [19:16] (see above) [19:16] saji89 asked: list.pop(i) will remove the ith element and return it. Returns it, as in prints it? [19:16] Not exactly [19:16] for instance, consider this case [19:16] if numbers.pop() > 0: [19:17] print "the last element of numbers is bigger than zero" [19:17] but that wouldn't work with del :) [19:17] Does that explain it? [19:17] If you want to put an element at some exact position, you have insert() for that [19:18] list.insert(i, x) will insert x at position i [19:18] HoellP asked: is pop how i would evaluate command line options? [19:18] No [19:18] if you want to see command line arguments, import the module sys and access sys.argv [19:19] For example [19:19] if we had numbers = [1, 2, 3] [19:19] we could do [19:19] numbers.insert(0, 0) [19:19] that would insert 0 at position 0 [19:20] But behold! [19:21] lists can hold elements of different types [19:21] (take that, C) [19:21] for instance [19:21] things = [1, "hi", 4.3] [19:21] here we have an int, a string and a float [19:22] Let's go over some more list methods and then go to slicing [19:22] We have: [19:22] list.extend(another_list) [19:22] this simply adds another list to a list [19:23] a = [1, 2] and b = [3, 4]. a.extend(b) = [1, 2, 3, 4] [19:23] this is different from a.append(b) [19:23] a.append(b) would result in [19:23] [1, 2, [3, 4]] [19:23] Yes, friends! Lists inside lists! [19:26] Say, we had, for instance [19:26] a = [[1, 2], [3, 4]] [19:26] len(a) == 2 [19:26] it has two elements, two lists [19:26] a[0] == [1, 2] [19:26] suppose we want the first element of a[0] [19:26] a[0][0] [19:27] That may look weird but it's perfectly fine [19:27] any questions? [19:28] We have some other methods [19:28] list.count(x) returns how many times x occurs in list [19:28] for instance [19:28] a = [1, 1, 2, 3] [19:28] a.count(1) == 2 [19:29] We also have the sort() method [19:29] this sorts a list in order [19:29] a = [3, 2, 4, 1] [19:29] a.sort() [19:29] a == [1, 2, 3, 4] [19:29] what if there are strings in the list? [19:30] a = ["b", "c", "a"] [19:30] a.sort() [19:30] a == ["a", "b", "c"] [19:30] Yes, it sorts alphabetically too :) [19:30] Otto48 asked: How does sort() handle different types? EG a = [1, "w", [5, 6]]? [19:32] you got me. Your example yields [1, [5, 6], 'w']. Python must have a priority hierarchy, but unfortunately it's not mentioned in the docs (or I couldn't find it) [19:33] You also have the function sorted(), which is similar to sort() [19:34] but sort() alters the list in place, and sorted() merely returns a sorted list [19:34] let me explain that further [19:34] a = [3, 1, 2] [19:34] a.sort() [19:34] now a == [1, 2, 3] [19:34] but what if we did: [19:34] a = [3, 1, 2] [19:34] sorted(a) [19:34] a STILL is [3, 1, 2] [19:34] because sorted() does not modify a [19:34] it only returns the sorted list [19:35] did you understand the difference? [19:36] great [19:36] saji89 asked: simply sorted(a) throws away the result. Isn't it? So we use b=sorted(a). Right? [19:37] Perfect, saji89 ! [19:37] You're grasping the concept [19:37] that is correct [19:37] We also have the list method reverse(), which reverses a list in place [19:37] a = [1, 2, 3] [19:37] a.reverse() [19:37] a = [3, 2, 1] [19:37] but it does not SORT the list in reverse [19:38] it merely switches positions [19:38] to sort it in reverse, do: [19:38] a.sort(reverse = True) [19:38] Questions? [19:39] Otto48 asked: does "a.sort(reverse = True)" hint at named parameters? [19:39] Yes [19:39] many functions called will have that [19:40] We'll be learning more about them in the session about functions [19:40] Let's have a quick look at for loops, and while if we manage [19:40] A for loop is a method of iterating over a list, or any iterable type [19:41] in this loop, we have a temporary variable that will be set to each of the values in the list, run the commands with, then changed [19:41] for instance [19:41] values = [1, 2, 3, 4, 5] [19:41] for val in values: [19:41] print val [19:42] Go ahead and try that [19:42] the example is fairly obvious [19:42] For each val inside values, print it === stalcup is now known as vorian [19:43] We may, however, raise complexity [19:43] Say I would like to only print the even values [19:43] you may recall how to check if a number is even [19:43] we use % [19:43] so [19:43] for val in values: [19:44] if not val % 2: [19:44] print val [19:44] Any questions about that? [19:45] Alright, that's good [19:45] We have time for while loops then [19:46] A while loop is a loop that's run as long as a certain expression evaluates to True [19:46] for instance [19:46] x = 5 [19:46] while x > 0: [19:46] x -= 1 [19:46] print "x is now %s" % x [19:47] go ahead and try that [19:48] Questions? [19:50] Otto48 asked: Does python have other loops? Does it have constructs similar to "Do ...Until" or "for (a=1;a<5;a+=)"? [19:50] Nope [19:50] python does not have a C-like for [19:50] no do while either, IIRC [19:51] But be not afraid [19:51] we can do it all with justs fors and whiles :) [19:51] Loops have two important keywords [19:51] break and continue [19:51] break stops a loop immediately [19:52] even_numbers = [2, 4, 6] [19:52] for x in even_numbers: [19:52] if x % 2: # x is ODD [19:52] break [19:52] we found a non-even number! [19:52] That stops the iteration completely [19:52] Each of the "loops" is called an iteration [19:53] and looping over is calling iterating [19:53] the keyword continue stops an iteration and moves on to the next [19:53] say we only want to print numbers greater than 0 [19:54] well, scratch that [19:54] hm.. [19:54] alright... my examples suck [19:54] but it's pretty simple [19:54] a = [1, 2, 3, 4, 5] [19:54] for x in a: [19:55] wait [19:55] pedro3005: x%2 = something suld be there, right? [19:55] I forgot to mention this [19:55] no, saji89 , we can do without it [19:55] say [19:55] x = 0 [19:55] if x: blabla [19:55] it will not run [19:56] if x: is just a way of saying if x == True [19:56] things that are == False: 0, "", [], [19:56] empty things [19:57] Questions? [19:58] Good [19:58] in these last minutes, I'll introduce you guys to two great resources for beginners [19:58] The UF beginner programming challenges - http://ubuntuforums.org/showthread.php?p=5499486 [19:58] You should be able to do problem 1 [19:59] * pedro3005 checks if stlsaint is around [19:59] No? Good [19:59] We also have another resource [19:59] http://projecteuler.net :) [19:59] It is a series of math questions [20:00] if you like math, they are great [20:00] You should also be able to solve the first problem from project euler [20:00] and the second [20:00] but they are REALLY hard [20:00] so if you manage, kudos [20:00] and if you're not managing, don't worry [20:01] with your amount of knowledge you could solve 1, 2, 6 and 5 :P === ChanServ changed the topic of #ubuntu-classroom to: Welcome to the Ubuntu Classroom - https://wiki.ubuntu.com/Classroom || Support in #ubuntu || Upcoming Schedule: http://is.gd/8rtIi || Questions in #ubuntu-classroom-chat || [20:01] This concludes the session [20:02] Next class I will be going over how to solve the 1st UF beginner problem and the 1st Euler problem [20:02] pedro3005: COol.... :) [20:02] I encourage all to try them [20:02] Well Done pedro3005 [20:03] pedro3005: I'll try the first ones in the two reaosurces. :) [20:04] saji89, I'll gladly take PMs [20:04] :) [20:04] thanks pedro! [20:04] thank you apperceptions , hope you liked it [20:05] pedro3005: Cool. [22:15] * etank is starting to think that the times on the classroom calendar are UTC and he is about 4 hours late === yofel_ is now known as yofel