51作业君
首页
低价平台
服务介绍
代写程序
代写论文
编程辅导
代写案例
论文案例
联系方式
诚邀英才
代写选择指南
程序辅导案例
>
Program
>
程序代写案例-IFB104
欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
IFB104 Practice Exam Solutions This document contains suggested solutions for the practice exam questions, plus a few hints on how to tackle them. r>Rationale The following are the ten assessable topics covered in IFB104’s lectures, workshops and assessment tasks, so you are expected to have a good understanding of them all. • Topic 1 – Expressions and assignment (and simple data structures) • Topic 2 – Calling pre-defined functions (and parameter passing) • Topic 3 – Defining functions • Topic 4 – Boolean expressions, predicates and conditional statements • Topic 5 – For-each and while statements, and recursion • Topic 6 – Graphical user interfaces • Topic 7 – Document mark-up notations • Topic 8 – Pattern matching • Topic 9 – Database querying • Topic 10 – Exception handling In the final exam these ten topics are grouped as follows to form eight large “skills-based” questions. The questions’ weights, the topics they relate to, and the kind of question are as shown. 1. Expressions and assignment (3%; Topic 1; multiple choice) 2. Calling pre-defined functions (4%; Topic 2; file upload) 3. Defining functions (4%; Topic 3; short answer) 4. Boolean expressions and conditional statements (4%; Topic 4; multiple answer) 5. Iteration (4%; Topic 5; multiple choice) 6. Mark-up languages and pattern matching (5%; Topics 7 and 8; short answer) 7. Graphical user interfaces (front ends) (5%; Topic 6; file upload) 8. Databases and exception handling (back ends) (5%; Topics 9 and 10; file upload) In addition, the exam tests what has been learnt from attempting the programming tasks, so the final exam ends with six brief “knowledge-based” questions, although the practice exam has only two of these. Even if you did not complete the tasks you should still be familiar enough with their requirements to answer basic questions about them. 9.–14. [practice 9.–10.] Programming tasks (6% on the final exam, 2% on the practice exam; Assessment Tasks 1 and 2; multiple choice questions) See the practice exam itself on Blackboard for the specific questions in the same style they will appear in the online final exam. You should ensure that you are familiar with answering these kinds of questions in your personal computing environment, including filling in text boxes, selecting answers from a list of choices, downloading template files and uploading solution files. We recommend using Firefox to complete the exam. In particular, we strongly advise against using Google Chrome, which has proven unreliable when used with Blackboard tests. Expected answers for the questions on the practice exam, plus some commentary, are as follows. Question 1 The expected assignment statement is as follows. coverage = abs(p[0] – q[0]) + abs(p[1] – q[1]) You should be able to determine the expression on the right-hand side by substituting each of the intermediate variables’ expressions into the assignment statements that follow them. If you attempt to answer this question by implementing the code note that for many values of p and q one or more of the incorrect answers will produce the same answer as the correct one, so several tests will be needed to distinguish them. For instance, if p is [1, 59] and q is [97, 80] then four of the five alternatives produce the correct answer! However, if p is [84, 6] and q is [68, 53] then only the answer above produces the right result. Aside: The code performs a meaningful calculation. It determines the “Manhattan distance” between two cartesian coordinates (p1, p2) and (q1, q2). Question 2 To answer this question you need to upload an executable Python program which draws the required image using Turtle graphics when run. There are many possible ways to achieve this, including the program reproduced below. Note that this is not the most concise solution to the problem. The code could have been reduced to about a third of its size using a parameterised function definition to position and draw the squares. However, this is likely the kind of unoptimised solution that someone would create under time pressure. Assessment for this question is based purely on functionality, not code quality. (It’s also not necessary to go to the trouble of positioning the image centrally.) # Import the Turtle functions and get ready to draw from turtle import * setup() pencolor('black') width(5) # Go to top RH corner of outer square and head 'north' penup() forward(100) left(90) forward(100) pendown() # Draw outer square fillcolor('red') begin_fill() for side in ['top', 'left', 'bottom', 'right']: left(90) forward(200) end_fill() # Go to top RH corner of middle square and head 'north' penup() home() forward(70) left(90) forward(70) pendown() # Draw middle square fillcolor('blue') begin_fill() for side in ['top', 'left', 'bottom', 'right']: left(90) forward(140) end_fill() # Go to top RH corner of inner square and head 'north' penup() home() forward(40) left(90) forward(40) pendown() # Draw inner square fillcolor('green') begin_fill() for side in ['top', 'left', 'bottom', 'right']: left(90) forward(80) end_fill() # Gracefully exit hideturtle() done() Question 3 There are two valid solutions to this question. One possible answer is the following function call. mystery(['c', 'a'], ['b']) To see why this works you need to trace the way the arguments in the function call above are passed through the code. In this specific example list ['c', 'a'] is used as the value of parameter puzzle in function mystery and list ['b'] is used as the value of parameter conundrum. Function mystery returns puzzle’s second value, the letter 'a', as the first item in the final list returned, which is the first part of our desired result. The rest of the list is created by calling function paradox with list ['b'] as the value of parameter riddle and list ['c', 'a'] as the value of parameter poser. (Be careful! Note that the order of the parameters in the calls to functions mystery and paradox are reversed.) Continuing to trace through the code in this way will show that the call to paradox returns list ['b', 'c'] and the call to mystery above returns ['a', 'b', 'c'] as desired. However, by observing that parameter conundrum already has a default value of ['b'] in the definition of function mystery we can solve this problem with an even simpler function call, as follows. mystery(['c', 'a']) Either way, you should check your solution by running the code before submitting your final answer, of course. Question 4 To solve this kind of problem you should consider the conditions necessary to reach the desired assignment statement(s). In this question we want to reach the assignment outcome = 'Fair'. To do this condition price > 1000 in the outermost conditional statement must be true and condition durability < 4 in the inner statement must be false. This makes the necessary condition to reach the desired assignment equivalent to the following Boolean expression. price > 1000 and durability >= 4 Using this knowledge you then need to identify the options that satisfy this condition. In this case there are two correct answers: • When price is greater then 1000 and durability equals 5 • When price is greater than 1000 and durability equals 4 Aside: The code makes a meaningful decision. It favours scenarios with lower prices and higher durability. Question 5 This is a ‘code comprehension’ question which tests your ability to understand program code by reading it, as an experienced programmer can. Although you can try running the code, doing so may not necessarily reveal its purpose. (This is why we place so much emphasis on commenting your code. It’s easy to see what some code does, but it’s much harder to see why!) To answer this question you need to study the code segment line-by-line to understand its behaviour: 1. It’s clear from the second line that it processes consecutive values from list numbers. 2. The fifth line tells us that each number processed has its square root added to variable sum_of_roots. 3. The third and fourth lines tell us that it stops iterating as soon as it encounters a negative number. 4. Finally, variable sum_of_roots is printed as the result. Putting all these facts together tells us that the correct answer is: • It prints the sum of the square roots of all the numbers in the list but stops at the first negative value, if any. Question 6 As is usually the case with pattern matching, the aim here is to construct a pattern that includes the results of interest and excludes all others. Typically this means identifying features of the text being searched that are unique to the desired results. 1. In this case the results we want are all email addresses, which we can characterise as sequences containing an “@” character and one or more non-space characters on either side. 2. However, there are many such addresses occurring in the document that we don’t want to return. The ones that we do want are all preceded by an emphasised name enclosed in a hyperlink. We can therefore exclude the unwanted addresses by requiring that matching patterns are preceded by ‘
’ end tags. One possible solution, therefore, is the following regular expression, expressed as a Python string. '.* (.+@.+)' Reading it left-to-right says: 1. First match the two ending tags ‘’. 2. Then match as many characters as possible up to a final space, ‘ ’ (which will be the last space on the line, i.e., the one immediately before the email address we want). 3. Then match one or more characters, followed by an ‘@’. 4. Then match one or more characters (up to the end of the line). The part in round brackets, matched in Steps 3 and 4 above, is the part of the overall pattern returned. As you have experienced when completing the workshop exercises and assessment tasks, getting a regular expression exactly right can be a tricky process, so you should consider using a regular expression tool to test your solution before submitting your answer. Question 7 Completing this question simply involves applying the programming skills you have gained with Python’s tkinter module by completing the relevant workshop exercises and assessment tasks. To complete this particular program you need to (a) associate a new function with the ‘Duplicate’ button and (b) define this new function which copies text from the text entry box into the label. The specific code needed to do this is as shown below, with the new parts highlighted in red. # Function for copying text from the entry box into the label def duplicate(): users_text = data_entry.get() if users_text == '': data_copy['text'] = 'EMPTY' else: data_copy['text'] = users_text # Create a push button that calls the above function when pushed Button(main_window, font = big_font, text = ' Duplicate ', command = duplicate, activeforeground = 'red').\ grid(row = 2, column = 0, padx = 5, pady = 5) Observation: It’s impossible to remember the many options and methods associated with the various Tkinter widgets. You should be prepared to look online for help with programming the specific Tkinter widgets used in the equivalent final exam question. There are many tutorials and references for Tkinter online, some better than others, so you should familarise yourself with a few good ones before the final exam. Question 8 Similarly to the previous question, here you are being tested on the Python and SQLite scripting skills you have acquired by completing the relevant workshop exercises and assessment tasks. In this case you need to (a) develop a suitable SQLite query and (b) write Python code to execute this query and fetch and print the result. The first of these is best done using the DB Browser for SQLite or an equivalent tool, and the second using your preferred Python development environment. In this case the necessary SQLite query, where the randomly-generated number of movies is a number N, is as follows. select count(actor) from actors where number_of_movies = N It’s then necessary to execute this query in the Python program, fetch the result and print it, appropriately formatted. There have been many simple ‘querying’ programs like this presented in the IFB104 teaching materials, including the ‘Access Superheroes’ demonstration from Lecture 9 and the ‘Connect to Database’ exercise from Workshop 9, so you should study the Week 9 materials before attempting the final exam. Question 9 Obviously the intended answer is the following. Use an argument in the function call to control whether or not function create_drawing_canvas writes the messages, without changing any of its code. Although facetious, this question makes a serious observation regarding professional practice when faced with specific instructions from a client. Question 10 Recognising that the main requirement for this GUI feature was to allow the user to select one category at a time, the odd choice out was the following. Checkboxes Checkboxes normally act independently of other widgets and multiple checkboxes can be selected at the same time, which would be confusing for the user when trying to select a single category. All the other options allow only one thing to be selected at a time.
欢迎咨询51作业君
官方微信
TOP
Email:51zuoyejun
@gmail.com
添加客服微信:
Fudaojun0228