Lecture Notes 07.11.22
QUIZ ANSWERS (Week 6 Moodle, PDF)
Q1: A. I mean, code isn't easy at the best of times, and functions add a lot of functionality. They make the code more modular, and can customise your script better, so you can use the same set of variables to run different commands. I could be wrong though
Answer: D. Basically, unless a client specifically requests the use of functions, they aren't necessary for that purpose.
Q2: B. As far as I remember, the whole point of writing functions in the first place is because you can call them anywhere in your script with the keyword you set when creating them. Unless of course I'm misremembering just what a return keyword is, because you don't necessarily need the print function. But I will stick with B for now, let's see how that works out for me.
Answer: D. So yeah, returns are technically optional, but without one a function will do nothing. Which makes sense.
Q3: I think A? The double seems like a red herring, as that's just the name of the function, not a command so it doesn't double anything. But at the same time, that's a crazy amount of brackets and I can't remember just what that does to the final code. I'm gonna run it through w3schools and see what I get. Well, I got an error. Something about needing an indented block, but that's on me because I can't quite figure out which bit is supposed to be indented.
Answer: None. The actual answer is 3,81. It is regular algebra, just remember that it was returned several times, so multiplied twice thanks to the command 'calc = x *x'
Q4: A, I think. As far as I remember that is the right structure for the command, but I can't remember if it needs brackets or not
Answer: A or B. Remember that the return has to come before the values, or it can't return a value
Q5: I think C. This is really driving home how little I actually remember, and how much I just brute force my code till I get past the errors
Answer: A. That is apparently the correct way to add something to a dictionary, you don't need the curly brackets like I thought.
Q6: Well it's either B or D. I just can't remember whether or not it needs a colon
Answer: D. It does in fact, need a colon.
Q7: A, I think, as the default value of target is 0
Answer: D. 'Target = 0' was only ran once as it was not in the loop. It might only have been printing the first value of i, but it was still multiplying. Once the loop ended, it printed the final value for the loop (which was 54)
Q8: A, at least as far as I understand the hint.
Answer: A. To be honest, I still don't understand it fully. But the loop is checking for uppercase letters, and adding them to a list (s.isupper). As it's the only one being checked, it gets added to the list. Stoychev then added a line under it, and it checked it for uppercase letters and added them to the script.
Q9: B, unless there's a syntax error I can't spot
Answer: B. Woo, actually got one. Main thing to remember is that 'and' forces both statements to be true, or it will be false.
Q10: D. I think this is an error, due to the value of y being in apostrophes making it a string, and you can't add both of them without converting them first.
Answer: D. That one was easy enough, don't mix your strings and your ints kids. The + will do nothing, as you cannot add a string value, unless all the values are strings.
Q11: A
Answer: Nice and simple, but I was wrong anyway. It's #, not //. That's Java.
Q12: B
Answer: I didn't catch that answer, but apparently it was simple
Q13: D
Answer: D. All good, remember the order of the values will match the orders of the function. (a,b,c will be 10,20,30 in that order)
Q14: A, I think, but that code is scrambling my brain
Answer: A. A roundabout way of doing it, but it still did it. Man I hate algebra.
Q15: B
Answer: B. That's what you get for doubting yourself and thinking it was C out loud. That value does go to 21, but as it is less than 20 it doesn't print that value.
Q16: C. Commenting is essential to remember just what the fuck you were coding, and why you coded it. This can help with debugging later, makes understanding your own code easier and while it might not be industry standard, it's common courtesy in case someone else has to modify your code.
Answer: C. Comments do nothing to improve the speed of your code, you just misread the question you tool.
Q17: D, I'm pretty sure
Answer: D. All of the other answers can be stored.
Q18: D. I'm pretty sure there's an error in there somewhere, probably due to mixing string, float and int values within the same function
Answer: 2. Apparently the answer was the 8/4, but this is still very confusing. Important thing to remember is that you can have multiple lists within a list.
Q19: I would guess B, I don't actually remember going over the break command
Answer: B. Break makes the loop break, very handy.
Q20: D. It's hurting my brain, so I'm hoping it'll hurt the scripts too. Apparently it's 20. No idea how
Answer: You're a dumbass. It doesn't matter how finicky dividing 2 by three is, if you immediately multiply it by 2 because it just goes back to 2.
Q20.5: Ohh, it's different versions of Python? I have absolutely no idea what the differences between them is. After looking it up, apparently Python 2 is the older version discontinued in 2020, and one key difference between them is that Python 2 rounded integers, whereas Python 3 does not. The example given was 5 / 2 = 2 (Python 2), or 2.5 (Python 3)
Answer: Also would be 20.
pynative.com/python-numbers-quiz/Bottom of week 6 on Moodle
Programming for Animation
Status | Released |
Category | Other |
Author | Ionasphero |
More posts
- Lecture Notes 28/11/22Dec 15, 2022
- Lecture Notes 28/11/22 Missing CodeDec 15, 2022
- Lecture Notes 24/10/22Dec 15, 2022
- Pre-Quiz Revision NotesDec 15, 2022
- Final Post before SubmissionDec 15, 2022
- Lecture notes 10/10/22Oct 10, 2022
- Lecture notes 03/10/22Oct 10, 2022
Leave a comment
Log in with itch.io to leave a comment.