 Gweithio am y cyd-dyniad, mae'n gweithio bod y sefydliad ar y cynnyddol gwahanol. Felly eu gwneud am yma. Yn Mylgrifennid Gweithio, dyna ym Mhwylgrifennid Gweithio, sy'n ei gweithio i'ch gwerthu'r genedlfa'r genedlfa'r genedlfa'r genedlfa'r genedlfa hwnnw. Ym mwyaf yn gweithio a'n mylgrifennid. Felly oeddwn i'n meddwl i'r gweithio, ac mae'n gweithio i'ch meddwl i'r gwirionedd. So on to the session then, what on earth is a python bee? Cystaf was created in 2008, a group of MIT students entered it into a competition for bad ideas, which it won and has suitably been run ever since. It is utterly ridiculous, it's great fun. So if you've heard of a spelling bee where you have to spell words out loud, so this is like that for programmes. So you have to spell like a single character at a time, your solution out loud. Yep, even the white space, even the punctuation, absolutely everything. You're not allowed to look at the code whilst you're doing this, so someone else will be typing it in for you. So the white space for one, you're probably immediately wondering tabs or spaces. We may get to several levels of indentation, I don't want anyone to have to sit there and remember if they said 12 or 11 spaces. So flame was a side, tabs, just to make our life easier. So we'll set our editors a tab for spaces and just avoid that conundrum. So how does this ridiculous thing work? We are going to give you an example. So I've set up a load of files, each of these has the module doc string contains what the problem is that you're supposed to do, then there are some tests and the idea is you write some code and the test pass. So in this case, somebody would read out the question to you, so they would say, write a function f, which takes arbitrary input, yet always returns hello world. So obviously they'd need to say out loud the capitalisation of that because you can't see it. And then you would go about writing a solution. So we have this thing here. So whoever is typing in for you will delete this and then you'll say the solution. So I'm not allowed to look at that. Death, oops, no. D, E, F, space. F, open parenthesis. Star, A, comma, space. Star, star, K, close parenthesis, colon. New line, tab. R, E, T, U, R, N, space. Single quote, H, oops, no. Backspace, capital H. E, L, L, O, space. Capital W, O, R, L, D, quote. Run test. Okay. And then someone will have typed that into for you. So you'll notice that most editors are going to put extra stuff in for you here. So you need to be really careful. If you can use a plain text editor, just like notepad or something, that would be great. If not, make sure if you're typing stuff in, you're deleting any extra characters. So again, you'll probably have auto indentation. So either set your editor so that isn't happening or just delete it for them. And as I said, either set it so tabs are for spaces or just type space four times if you really can't bring yourself to these tabs. So, right. So we now run these tests. That was correct. So it'll return silently if everything worked. If say you'd, I don't know, got enthusiastic and put an explanation mark in there, you'll have some test failures. So that's going to be the idea. Are we going to set this up? Oh, so actually some hints. So as I said, you can set back space if you make a mistake. If you're getting to lots of sort of nesting and you want to track where that's going, I advise like your fingers are a useful stack. You can pop back out as you want to track indentation. Parentheses, square brackets, be really clear about what you mean. So it's open and close parentheses, open and close square or curly brackets. Be very clear. Similarly, if you want an uppercase character, or whatever, otherwise they'll assume an uppercase. I wouldn't get carried away and worry about elegant solutions and performance here. Just make the code work. Yeah. So scoring. So we're going to have a set of these test files. If it returns silently, it was successful. You get some points. You don't get another go if it fails. The questions are divided up into easy, medium, hard. Where hard is bearing in mind, you're not allowed to look at the code and this is entirely ridiculous so you get a different number of points. One, two and three respectively. Just keep a mental note of your score. We'll try and declare an overall winner at the end. And no peeking at the questions slash doing one that you've just seen someone else do. That takes the fun out of it. Just be honest, I'll do that. Set up. So we're going to try and group so about three. You only need one laptop between you. So if you have any set of issues, just put your laptop away and use someone else's that works. The idea is any one time, if you're typing, it'd be really annoying if someone just put a typo in and that caused you to not get the right answer so that's why two people watching over. And then about 10 minutes each and then we'll swap over. The questions are up on GitHub at that link there. As I said, try and use a plain text editor or set things up so that tabs are for spaces or to indentations off, that sort of thing. Agree on your version of Python. I've tested these questions with both two seven and three six. I need to know which one it's set to use. And standard Python library only. And yeah, have a go. Against groups, if anyone's got any questions, put your hand up and I'll come around. Yeah. So it started. One final comment. You might find the easy questions potentially quite boring there there in case there are any people who are really quite new to Python. So probably medium or above if you've been using it a while. It's got a title, everything. No, I would like you to not record it. Thank you. It was nice to see you. We should. Dave had a practice one. You could just pick any one. It's fine. This guy's a pep one. I think he gets hard ones. You were what? He's written some peps. Oh, I see. I think you have to use your hands in your solution. If one of the questions is publish a package to Python, yes, you can use one of his peps. We can't use any of my peps because we're not going to introduce one more cool stuff along. It's fine, isn't it? It's a good number. It's a good number. It's a good number. It's a good number. It's a good number. It's a good number. It's a good number. How does it work if we didn't even get all the details there? Yeah, I mean, this is going to be a pretty hard question even if you were typing. And this is a helper function. This is a helper function in their verb, right? Factorual? Yeah, factorual. Factorual. Factorual. Factorual. Factorual. Factorual is one you see Wel, ac mae'n gweld yn gweld yn y tyl enwedd yn eto, ac mae'n gweld yn ddodd meddwl siarad, maed yn werth tspwad. Mae'n gweld yn gweld yn gweld yn digwyddol, ac mae pen yn gweithio i ddylun am y gwelafethau sydd gyd. Rwy'r meddwl fan mwy o'r panrho! Mae'n meddwl ychydig yn gweld yn iawn i gweld yn gyfryd! Rwy'n meddwl â'r tref! Mae'n meddwl yn eich gweld yn y dy hosts! Mae'n meddwl yn eich gweld yn ei wneud i fi wneud i chi'n ddodd meddwl i'w gweld yn ei hollwch. Can I have a look at the doctor's sign? Since now I'm only going to do it. Yeah, so you can check that. That last case didn't... I can sit at a look up table, but that last case is fairly big. Oh, I have a great idea that I'm going to say for a really hard one now. Time to swap over if you haven't done so yet. OK, OK, here we go. DEF, space, F, open-paran, I, close-paran, colon, new-line, tab, I, F, space, I, equals, equals, 0, colon, R-E-T-U-R-N-E, space, 1, new-line, tab, R-E-T-U-R-N, space, F, open-paran, N, minus, 1, close-paran, asterisk. I need to go back and change the ends to I's left arrow, left arrow, left arrow. Actually, control A, delete. Just for the function. Never getting around is not going to work. I'm going to say exactly the same thing, but with I instead of N. If you just want to fix those up and go back to the asterisk, then that's fine by me. Back to the start. This is recorded now. OK, DEF, space, F, open-paran, I, close-paran, colon, new-line, tab, R-E-T-U-R-N, space, 1, I, F, space, I, equals, equals, 0, E-L-S-E, space, I, asterisk, F, open-paran, I minus 1, close-paran. Happy. All good. It's a Python 3.5, right? Yes. So, as of Python 2.7, and you are actually getting the syntax error for that? You shouldn't be. There's no syntax error in that. That's fine. They're unambiguous. You don't need spaces between unambiguous tokens. I actually voted to not fix that bug, but in Python 3.4.2, I think, or 3.4.3, someone complained that 0 else should have, like, was being parsed incorrectly, because it was being parsed as 0E. Oh, L is not a valid exponent syntax error. And they were saying that 0 else are true unambiguous tokens, and you shouldn't have to put a space between them, so we fixed the parser to go back if we found digit E non-digit, we'd go back and say, it's a number followed by E rest of whatever that token is. So, yeah, this is what happens when I get easy questions. Now I get a meeting one, do I? Just jump straight into the advanced ones. I have my trick. I have another trick. I just want to show off my trick. I'll give an advanced one. My trick was going to be import sys.exit 0, but Doctest might be smarter than that. Ff, which, given a positive integer, returns the value of a Roman numeral, where in Roman numerals, I equals 1, V equals 5, X equals 10, L equals 50, C equals 100, D equals 500, those are all lower case. The value you return should use as few characters as possible, e.g. 4 should be IV rather than IIII. You can assume that the number you have to convert is less than 1000, and the tests allow you to output the number in either lower case or uppercase, but it has to be consistent. I'll hold the microphone while I take my pass with me. I cannot do subtraction with the N, but I can do L0, XC, and 3 of something. 3 would be I. I can repeat. It was a function F, right? Df, space, C, open paran, I, close paran, colon, new line, tab, WHLE, space, I greater than equal to 500, colon, enter, tab, tab, I, minus equals 500, enter, tab, tab, Y, I, E, L, D, space, yield. Y, hang on, Y, E, I, L, D, that's what I said. It might not be what I said. Shift, home, delete. I hope that works on your keyboard. Cut line, tab, tab, Y, E, I, L, D, space, single quote, D, close single quote. New line, tab, IF, space, I greater than equal to 300, colon, new line, tab, tab, IF, space, I greater than equal to 400, colon, new line, 400, colon, new line, tab, tab, tab, Y, E, I, L, D, space, single quote, C, single quote, enter, tab, tab, tab, plus equals 100, new line, tab, tab, Y, E, I, L, D, space, single quote, C, D, single quote, new line, tab, tab, I, minus equals 400, new line, tab, W, H, I, L, E, space, I greater than 100, backspace, backspace, backspace, equals 100, colon, new line, tab, tab, I, minus equals 50, new line, tab, tab, Y, E, I, L, D, space, single quote, C, single quote, tab, IF, space, I greater than equal to 80, colon, new line, tab, tab, IF, space, I greater than equal to 90, colon, new line, tab, tab, tab, Y, E, I, L, D, space, single quote, X, single quote, I'm totally off now, new line, forge ahead, forge ahead, I shouldn't be into the tens yet, tab, tab, tab, I, plus equals 10, new line, tab, tab, Y, E, I, L, D, space, single quote, X, C, single quote, new line, tab, tab, I, minus equals 9, 0. It's time to swap over again if you just finished the question you're currently doing. New line? This must look so good. We should be getting what you're typing on the screen for people who are watching because this is going to be a really boring video otherwise. Yeah, that's probably a good idea. I think I'm so far wrong with this and I'm not going to get any good score anyway. Okay, let's bail out and just go for successful test. Tab, W-H-I-L-E, space, I greater than 0, colon, space, new line, tab, tab, Y, E, I, L, D, space, single quote, I, single quote, new line, tab, tab, I, minus, equals 1, new line, new line, D-E-F, space, F, open paren, I, close paren, colon, new line, tab, R-E-T-U-R-N-E, space, single quote, single quote, full stop, J-O-I-N, open paren, C, open paren, I, close paren, close paren. I gave up. Some of those numbers are going to have a lot of eyes in them. Oh, really? It is Y-I-E-L-D? Damn American spellings. What? Did I have an E on the end of? I did not. I did not. We have video proof. R-E-T-U-R-N. There's no way I would have put an E on the end of that. That means space. I always do that with the yield as well. Yay! The first test was one, wasn't it? It went, yeah. My second plan then is import OS.exit zero. But I suspect that Doctest is going to catch system exit and report that as a failure. There you go. Must be your turn, Thomas. Let's get up on the screen so we can actually record the typing. Can we use your microphone? No, because you're going to get the microphone. He hasn't been looking through all the other ones while you were sitting there, right? What's your PhD in again? All right. What medium would you like? Bouncing and proof? Checking your proof? Is it balanced or...? Balanced parentheses. No, I have to decide. Do you want to give it a go? Okay. Someone likes to type and I'll check everyone else's. Order matters only count. You're on camera for this one. You've got to look good. I mean, yeah, you can see what I'm typing. Just let me know if I type something wrong. I might type something wrong because I'm not used to this keyboard layout. But I'm basically hunting and packing as well. So I'm basically hunting and packing here as well, so it's not going to matter. Has anyone gotten a score above zero yet? Everyone has zero. Oh, dear. We're just doing one on the video, so don't mind us speaking into the room. You ready? Thomas is ready. Go. D E F space F open parentheses S closed parentheses C on. Okay. New line equals zero. New line tab for C in... Oh, sorry. I have to spell these out. F O R space C space I N space S colon. Just five minutes, and we're going to do the second half of a different exercise. New line tab tab I F space C equals equals single quote open parentheses single quote colon. New line tab tab tab P plus equals one new line tab tab E L I F space C equals equals single quote closed parentheses single quote colon. New line tab tab tab space P equals equals zero colon new line tab tab tab R E T U R N space capital F A L S E new line tab tab tab minus equals one new line tab tab tab tab R E T U R N space P equals equals zero save and run tests I don't even know what you're working in here. Congratulations. Okay, well done. It's a good place to stop, so I'm going to go on to the second half. If we can all just stop there where we are, I'll knock out once. So, because that wasn't absurd enough now we have something completely different. Co-op mode. So, I'm going to write code as a group, so you get to write a single character and then the next person gets a character. You do get to look at the code now, which is more helpful. You're not allowed to talk to each other, you're not allowed to do any hand signals, no communicating, no complex sequence of winks or anything like that. Absolutely no talking. I suggest you just pass the laptop round and enter one character at a time. I have tried this before. We were a group of people in the pub. Half of the people there had never done any Python, one person had never programmed at all. It went badly wrong, would be suffice to say. Turned into a ridiculous stack of overflow questions, see if we could get the thing to run at all. It'll either go that badly and it'll have a lot of fun or you might even get it to work. So, probably groups of six, so if you get together two groups of three together, if you get a solution right, you get two points each of one in the group. There is a folder called group in the project tree, so you try the exercises from that. And we've got about 15 minutes to have a go. So, go for it. You've got to do one from group. So, would you like to calculate a median? Do the nth of an Archie number or a slightly, quite a lot easier, reverse some words in a string. Remember, you can still do backspace with the person before you does something utterly ridiculous. So long as you have a majority of the people in agreement with deleting what's going on, you've got to do one from group. See if you can do a median. If that's all right. I think you should shout out the letter into the microphone as you practice it. Yes, I agree with that. So, in this one, we're writing a function f, which, given a list of numbers, calculates the median value. If the list is empty, return none. As Thomas just suggested, this is power mode, which means you need to shout out the letter you're typing as aggressively as you can, and then move on. I think we're just going to rotate around the stage, like a congeline. No, let's just jump from the stage and go around. So, we have our order sorted out. We don't get to communicate once we start. This is the order. No, you've got one backspace and then you've got to go off and the next person has to do it. Let's just do four. I mean, if there are people sitting here that are not joining in, then how can you join in? No. D, we've started. Go. E. Eks. No, just kidding. Open parenthesis. Closed parenthesis. Let's go. The right space is okay? Yeah. We'll let the others do what they can do because we can see what we're doing. Now is the time to think. N. S. It's all of my good development practices. I don't know. Okay, it doesn't have to be good. Okay. I have honestly no idea. So, yeah, that's communicating. But yeah, I was thinking along those lines. Right space. T. Open parenthesis. Should I be after the... Yeah, okay. But I guess we're a bit confused. Closed parenthesis. New line. F. T. Space. I feel like this is just getting more confusing every time. Well, space. Okay, let's do big space. New line. R. E. D. U. R. Sorry. N. New line. Oh, backspace. Good. U. N. Space. Open square bracket. I have no idea what we're going to do with the square bracket. Um... Backspace. I think they're backspace. Square bracket. Backspace. Backspace. Just got to say one character outside. Um... Period. You know what? Sorry. I didn't... Never mind. Just space. Um... Backspace. I wasn't confused unless you deleted my howl in records. Well, I... You have a chance to others. Space. Backspace. Backspace. We've got about five minutes left. So, yeah, good luck. We've been asked to give a hint to the team, which I guess I'll do. I'm feeling nice. So, look at the second test case that's been requested by one of your team members. Well, so I'm meant to be looking at the second test case. I think we're clearly not because we've been... I've been exactly here before. Backspace. Backspace. I concur now. You are. So, somebody gives my life a shift component. Yeah. Let's just do that and get it done. Yeah, okay. I'm sorry. Yeah, but the second test... Press something. Space. Sorry. Uh, crap. How do you do this on a Mac? I need you shifting. It's okay. Tab. Um... That's true. New line. Okay. It's going to be a lot of typing. You can do it this way. So, the definition of this medium is with the centric values, because there are a number of values of what the mean of the right centric value is that there's a million more values. So, if there's an exact amount in order to argue it, if there are two equally, because there's an even number of results, you take the mean. That's what it's going to be. In some definitions, you take a little one. In some, you take the higher one. In some, you take the mean of the two, and we're taking the mean of the two in the middle if there's an even number of outputs. L. E. Tab. Okay, what now? Closing parentheses? Yeah. Cologne. Oh, sorry. Space. Persent. Oh, sorry. Persent. Yeah. Equals. Equals. Zero. Cologne. Enter. One minute. Tab. N. Scriber. Slash. Oh, sorry. Slash. Slash. Two. Yeah, like two characters. Okay, I guess. I'm not sure if this is going to overwrite it, but I want to just close that. Close it in the square brach. All right, that's character then, Madam. You run it? Sorry. I can run it and see how much you actually got, if you want. It's two out of six past. So, you know. All right. I'm afraid that is all we have time for. So, if we can just sum up at the end and try and figure out who won. Thanks. So, if I could just have all your attention for a minute, you can carry on playing afterwards, if that's what you want. If we could just have quiet for a second. Thank you all for playing. I hope you enjoyed that. Thank you for Cambridge Medical Robotics for allowing me to put the conference this week and run the session. So, we are hiring. So, if working surgical robots sounds cool, then please check out the website. Welcome to me afterwards. So, scores. I hope you all made a mental note of your scores. We're going in for a simple one. The winner gets this exciting Python Easter sticker I picked up at the O'Reilly desk yesterday, which I've written you were a Python, Python B champion on. So, it's an ultimate prize. So, if you, everyone puts their hands up, and then if you keep your hand up, if you got the score that I'm able to say, or higher. So, if you all lift your hands up. Okay. One. Excellent. Two. Right, we have a joint winner, both on one. I suggest you take half of the sticker each. A random applause for our winners. I will leave your sticker here. Congratulations. So, yeah, I hope you all have fun. You can play this anytime you like in a pub or in the hallways afterwards. Yeah, I hope you enjoyed it. Thanks.