CMPT 120, Assignment CW 6.1
GUIDED PRACTICE TO START USING THE SYSTEM CODEWRITE AND ASSIGNMENT 6.1 DESCRIPTION
Deadline: Tuesday March 10, 11:59 PM
Aim to finish with the exercises earlier than the deadline.
Working in this assignment will at the same time help you prepare for the Midterm
You can see the solutions for each of the Codewrite (CW) exercises done by the instructor and by all
your peers after you solve the question.
After the deadline, the instructor solutions will be posted as review material.
You will be able to keep working with CW after solutions are posted, but not for points.
Learning to program, just like any skill, requires practice. An effective way to practice programming is to write
lots of short fragments of code (each only several lines long) so that you become comfortable with the syntax of
the language. At the same time, you learn the basic principles of programming and build your confidence so that
you feel ready to tackle more complex tasks.
The Codewrite tool has been developed in the Computer Science department, University of Auckland, New
Zealand, as part of Computing Science Educational research. We are using this tool at SFU in our course as part
of our learning tools and also as joint educational research to support the learning of students in both
Codewrite is just another environment to execute Python programs. It is designed to help you practice by
presenting you with lots of short exercises. To solve each exercise in Codewrite , you need to write (define)
one single function – that is, you are given the name of the function, a description of its intended behavior as
well as the parameters to the function and a description about how to calculate the value to be returned from
ARGUMENTS TO THE FUNCTION ARE PREPARED IN ADVANCE IN THE TEST CASES. YOUR FUNCTION
DEFINITION SHOULD NOT ASK ANYTHING TO THE USER, BUT RATHER USE THE PARAMETERS WHICH
WILL RECEIVE THE VALUES FROM THE ARGUMENTS IN THE TEST CASES.
CMPT 120, Assignment CW 6.1 Page 2 of 4
Instructor: Diana Cukierman
For example, the function (very simple but just included to illustrate):
def sum2 ( a, b):
named as sum2 should return the sum of the two parameter variables (a and b), assumed to be numeric. To
solve this exercise in Codewrite you would need to write the function including the def statement and
indentations just as you have done in a .py file within the IDLE environment or repl. You can solve this
question in various ways, typing the code directly in the window in Codewrite, such as:
or also naming the parameters differently:
or also directly returning the expression:
or also without parenthesis in the return statement:
IN CODEWRITE, IT WILL BE USUALLY THE CASE THAT YOU NEED TO __RETURN__A RESULT
THAT IS: WE WILL AIM THAT ALL FUNCTIONS IN CODEWRITE ARE FRUITFUL OR PRODUCTIVE (I.E .
RETURN A VALUE). Printing is possible, but limited to a small area and only to be used for tracing while
debugging, but not to solve the problem.
TO SOLVE ONE EXERCISE YOU WILL ONLY HAVE TO CREATE THE FUNCTION CODE (INCLUDING, the def
statement, with the function name and parameters) , and AGAIN, RETURNING THE RESULT
THE TEST CASES AND CALLING (INVOKING) THE FUNCTION for different cases IS ALREADY PRE‐DONE by
the inventor of the exercise (the instructor, in this assignment)
The system will automatically indicate if your code correctly solves the function for each one of the test
cases. The test cases include a mystery case that your code will also have to solve correctly.
result = a + b
return (a + b)
result = n1 + n2
CMPT 120, Assignment CW 6.1 Page 3 of 4
Instructor: Diana Cukierman
REGISTERING AND LOGGING INTO CODEWRITE
Begin by going to the CODEWRITE for SFU page: (Link available from the More Links section in the course
website and the home page)
Before using Codewrite , ONLY ONCE, you will need to register as a Codewrite user.
The registration process is guided. Follow the instructions provided by Codewrite. For Step 1 and Step 2 of the
registration you choose what you want to use.
For step 3 and step 4, you need to know that :
The “Codewrite course id” for Assignment #6.1 is: 72
The identifier (which we will also refer to as Codewrite identifier) should be your usual SFU user login ID (i.e.
the part that is in your SFU email account, without the ‘@sfu.ca’ part, the short version, preceded by D1 if you
are registered in the morning section or preceded by D2 if you are registered in the afternoon session .
For example: if Harry Potter has email address email@example.com and firstname.lastname@example.org, and he is
registered in the afternoon section, his Codewrite identifier will be: D2hpotter23
For username you may use the same as your identifier or other – it is your preference
To complete the registration follow the instructions provided. You will need to provide an email address and you
will be sent (to that email address) some code which you will have to use to complete the registration; you will
be guided through this process.
After you have registered once, you can login as many times as you want (while the Codewrite “course” (i.e.
this assignment) is opened) and you will also be able to participate in more Codewrite “courses” or
assignments in future assignments.
When you first log in Codewrite , you will see Assignment 6.1 appear on your list of available Codewrite
“courses”. Follow that link.
You will find that there are exercises available for you to solve (following the link: “view >>” under
“Unanswered Questions” .
CMPT 120, Assignment CW 6.1 Page 4 of 4
Instructor: Diana Cukierman
You will see a list of unanswered questions.
As you solve the exercises you may try as many attempts as you need (and points will not be affected) , i.e.
you can revise and test your code many times – do not worry about making mistakes. Every time you make a
mistake, it is an opportunity to learn. The system will inform you of syntax errors and also will inform you if,
even if your code is correct from the language and syntax point of view, it does not solve the problem (likely
because of a logical error).
Try first to not solve correctly the practice example (topic PRACTICE) sum and see what happens. For example,
try returning on purpose the multiplication of both numbers instead of the sum, etc.
Once you are done with your PRACTICE questions , solve the “REQUIRED” questions.
Everyone will receive 1.5 to work in Codewrite, 1 point for solving correctly each of the three PRACTICE
questions plus 2.5 points for each of the 11 REQUIRED questions correctly solved . To solve correctly an
exercise ALL TEST CASES HAVE TO PASS.
Given the marking scheme, everyone may get up to 32 points: 1.5 + 1*3 + 2.5*11 = 32 points
You should not submit this assignment via Canvas; rather, your assignment is submitted directly via Codewrite
End of guided working with Codewrite and assignment #6.1 description
One exercise (i.e. one function) is considered solved if it is CORRECT FOR ALL THE TEST CASES (ALL PASS).
The number of unanswered questions
depends on how many are available for
you to solve at the moment.
You can choose to list exercises of
specific topics. For this assignment you
will want to solve those with topic
“REQUIRED”. For practice solve those
classified as “PRACTICE”. Both types are
given points if you solve them.
本网站支持 Alipay WeChatPay PayPal等支付方式
E-mail: email@example.com 微信号:vipnxx