Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Department of Computer Science and Information Systems Birkbeck College, London Introduction to Programming IN-LAB-TEST MAY_PYTHON VERSION MARKING SCHEME 6th May 2016 This test is closed book. Access to the internet is not allowed except for the uploading of a single file containing your program to Moodle. Mobile phones, calculators, laptops, USB memory sticks and other electronic devices are not allowed. Instructions Create a new folder in your disk space with the name InLabTestMay. Launch the Python Integrated Development Environment IDLE. Begin with the Start icon in the lower left corner of the screen. If you are in a DCSIS laboratory then follow the sequence Start -> All Programs -> Python 3.4 -> IDLE (Python GUI) A window with the title Python 3.4.1 Shell should appear. If you are in one of the ITS laboratories MAL 109, MAL 457 or MAL 458, then follow the sequence Start -> All Programs -> Departmental Software -> Computer Science -> Python 3.4 -> IDLE (Python 3.4 GUI – 64 bit) A window with the title Python 3.4.4rc1 Shell should appear. In the Shell click on File. A drop down menu will appear. Click on New File. An Editor window with the title Python 3.4.1:Untitled (DCSIS) or Untitled (ITS) should appear. In the Editor, click on File, and then in the drop down menu click on Save As… . A window showing a list of folders should appear. Find the folder InLabTestMay and double click on it. In the box File name at the bottom of the window type InLabTestMay.py, and then click on the button Save in the lower right corner of the window. The title of the Editor should change to show the location of the file InLabTestMay.py. At the end of the test upload the single file InLabTestMay.py to the Assignment InLabTestMay in Moodle. There are three questions. Question 1 is worth 40 marks, Question 2 is worth 30 marks and Question 3 is worth 30 marks. Answer all three questions. Introduction to Programming in-laboratory test May 2016 Marking Scheme Page 1 Plagiarism Warning Students are reminded that the Department and the College apply a very strong policy in cases of plagiarism. Helping other students or taking advantage of help from other students during the test are considered to be plagiarism. Any excessive similarities between the work of different students will be carefully checked. The lightest penalty in case of plagiarism for those involved will be a mark of 0 for the whole test. Students caught during the test communicating with others by any means will be asked to leave the laboratory immediately and will be given a mark of 0. The following list of Python statements may contain entries which can be adapted as necessary to form parts of the answers to this test. ## This comment is important because it provides information necessary for # understanding the purpose of this file. # @param describe the parameters # @return describe the nature of the returned value # @author John Doe # @version 6.5.16 # if x == 4 : print("x:", x) for i in range(5) : print(i) for letter in string : print(letter) from math import sqrt x = int(input("Enter an integer: ")) i = len("string") ch = "string"[2] string47 = str(47) def newFunction(n) : print(2*n) return 2*n Introduction to Programming in-laboratory test May 2016 Marking Scheme Page 2 Question 1 (40 marks) Place a short comment at the head of the file InLabTestMay.py to identify the purpose of the file, the author and the date. Write a function with the following header def salary() : The function salary prints out the prompt Please enter your salary: and then obtains the salary from the keyboard. The salary is returned by the function salary in the form of a floating point number. Place a short explanatory comment immediately before the definition of salary. Make one call to salary to test the code. Use print to display the result of the call in the Shell. Transfer the result “by hand”, i.e. by manual typing, from the Shell to a comment placed after the call to salary. In the comment write out the number input to salary at the keyboard and the corresponding number returned by salary and printed in the Shell. Marking Scheme for Question 1 1. Comment at head of file (10 Marks). Comment for salary (5 marks). Total 15 marks. 2. The code is implemented in a reasonable way, ignoring minor syntax errors such as a missing : or incorrect indentations (15 marks), compiles and runs correctly (5 marks). Total 20 marks. 3. One call correctly reported in the comment. Here “correct” means that the output of the implemented function is correctly described. It does not necessarily mean that the function is a correct answer to the question. 5 marks. Question 2 (30 marks) Write a function with the following header def numberOfChildren() : The function numberOfChildren prints out the prompt Please enter the number of your children: and then obtains a number n from the keyboard. If n is strictly negative, then numberOfChildren prints out the error message Error: a number greater than or equal to 0 is required. and then repeats the prompt. This cycle is repeated until a number greater than or equal to 0 is entered. This number is returned in the form of an integer. Place a short explanatory comment immediately before the definition of numberOfChildren. Introduction to Programming in-laboratory test May 2016 Marking Scheme Page 3 Make one call to numberOfChildren to test the code. Provide as input to numberOfChildren three integers strictly less than 0 followed by one integer greater than or equal to zero. Use print to display the result of the call in the Shell. In a comment placed after the call to numberOfChildren i) list the sequence of integers input during the call; ii) confirm or otherwise that the error message was printed out for each negative input; iii) confirm or otherwise that the final integer in the input sequence was returned by numberOfChildren. It is not necessary to write out the error message in the comment. Marking Scheme for Question 2 1. Comment for numberOfChildren. 5 marks. 2. The function numberOfChildren is implemented in a reasonable way, ignoring minor syntax errors such as a missing : or incorrect indentations (15 marks), compiles and runs correctly (5 marks). Total 20 marks. 3. One call correctly reported in the comment (see the marking scheme for Qu. 1). 5 marks. Question 3 (30 marks) A non-governmental organization provides financial assistance for families. The formula is as follows: If the annual household income is greater than or equal to $30,000 and strictly less than $40,000 and the household has at least three children, then the amount is $1,000 per child. If the annual household income is greater than or equal to $20,000 and strictly less than $30,000 and the household has at least two children, then the amount is $1,500 per child. If the annual household income is strictly less than $20,000, then the amount is $2,000 per child. In all other cases the amount is $0. Write a function with the following header def assistance(s, nc) : The argument s is the salary in dollars and the argument nc is the number of children. The function assistance returns the value specified by the above formula in the form of an integer. Place a short explanatory comment immediately before the definition of assistance. It is not necessary to include the formula in the comment. Make five calls to assistance to test the code. Use print to display the result of each call in the Shell. Copy the results by hand from the Shell to a comment following the five calls to assistance. The order of the results in the comment should be the same as the order of the calls by which they were produced. Introduction to Programming in-laboratory test May 2016 Marking Scheme Page 4 Marking Scheme for Question 3. 1. Comment for the function assistance. 5 marks. 2. The function assistance is implemented in a reasonable way, ignoring minor syntax errors such as a missing : or incorrect indentations (15 marks), compiles and runs correctly (5 marks). Total 20 marks. 3. One mark for each call correctly described in the comment (see Qu. 1). Total 5 marks. Introduction to Programming in-laboratory test May 2016 Marking Scheme Page 5