Exam 2017, questions PDF

Title Exam 2017, questions
Course Introduction to Programming in Python
Institution University of Essex
Pages 6
File Size 180.6 KB
File Type PDF
Total Downloads 14
Total Views 135

Summary

Exam from 2017 with Section B...


Description

CE151-4-AU UNIVERSITY OF ESSEX Undergraduate Examinations January 2017 ___________________________________________________________________________ INTRODUCTION TO PROGRAMMING

Time allowed: TWO hours

Candidates are permitted to bring into the examination room: Casio FX-83GT Plus or Casio FX-85GT Plus ONLY

Candidates must answer ALL THE QUESTIONS in SECTION A on the machine readable form and ALL THE QUESTIONS from SECTION B in the written answer booklet.

The paper consists of TWENTY NINE questions, TWENTY FIVE in SECTION A and FOUR in SECTION B.

SECTION A is worth 40% of the total mark for the question; each of the questions in this section is equally weighted.

SECTION B is worth 60% of the total mark for the question; each of the questions in this section is equally weighted.

The percentages shown in brackets in SECTION B provide an indication of the proportion of the total marks for the PAPER which will be allocated.

Please do not leave your seat unless you are given permission by an invigilator. Do not communicate in any way with any other candidate in the examination room. Do not open the question paper until told to do so. All answers must be written in the answer book(s) provided. All rough work must be written in the answer book(s) provided. A line should be drawn through any rough work to indicate to the examiner that it is not part of the work to be marked. At the end of the examination, remain seated until your answer book(s) have been collected and you have been told you may leave.

CE151-4-AU

2

SECTION A Answers to questions in SECTION A should be written on the machine-readable answer sheet. Each question is SECTION A is worth 1.6% of the total mark for the paper.

SECTION A IS NOT AVAILABLE

CE151-4-AU3

SECTION B Answers to questions in SECTION B should be written in the answer booklet provided.

Question 26 (a)

Explain what is meant by a runtime error and give examples of three different kinds of runtime error in Python.

[5%]

(b)

The following Python program contains three errors that will be detected by the IDLE syntax-checker. For each of these errors, state the number of the line on which it occurs and how it should be corrected.

[6%]

01 02 03 04 05 06 07 08

(c)

x = int(input("Enter value for x")) print("The square of x is" x * x) y = input("Enter value for y") print("The product of x and y is", x * y) if x > y print("The difference is", x – y) else : print("The difference is", y – x)

The above program, when corrected, should input an integer, x, output its square, and then input another integer, y, and output the product of x and y followed by the difference between x and y. However it contains another error that causes it to behave incorrectly. Describe how the program would behave if the user supplied values of 5 and 15 for x and y, and also describe the additional correction that must be made in order for the program to run correctly.

[4%]

CE151-4-AU

4

Question 27 (a)

Write a Python function called isHexDigit, which takes a string as an argument and returns True if its argument is a single-character string with a value that is used in hexadecimal numerals (i.e. in the range ’0’ to ’9’ or ’a’ to ’f’) but returns False otherwise.

[4%]

(b)

Write a function that takes a string as an argument and makes several calls to the isHexDigit function in order to calculate and return the number of occurrences of hexadecimal digits in the string.

[4%]

(c)

Write two separate functions, which take as arguments two strings and a positive integer n, and returns True if the first n characters in the first string are the same as the first n characters in the second string (in the same order) and returns False otherwise. You may assume that both strings contain at least n characters.

[7%]

The first version should use a loop to compare the characters individually; the second must not use a loop.

CE151-4-AU5

Question 28

(a)

Write a Python function called maxProd, which takes as an argument a list of sets of numbers, calculates the product of the values in each of the sets, and returns the largest such product. (Note that the sets may contain negative numbers so the largest product could be negative.) If any of the sets is empty, its product should be treated as 1; if the list is empty, the value None should be returned.

[9%]

(b)

The greatest common divisor (GCD) of two positive integers m and n can be calculated using the following definition:

[6%]

If m and n are equal the GCD of m and n is m. Otherwise the GCD of m and n is the GCD of x and y, where x is the difference between m and n, and y is smaller of m and n. Use this definition to produce a recursive function that takes as arguments two integers m and n and returns their greatest common divisor. You may assume that the arguments supplied in calls to the function will always be positive.

6

CE151-4-AU

Question 29 A file containing data about a collection of lecturers has the following format. Fred Smith 28000 CSEE Jim Brown 33000 Sociology Ann Simpson 31000 CSEE Each line contains a first name, a second name, a salary (in pounds) and a department. Write a complete Python program that will input the contents of the file into a list of tuples, and output full details of the lecturers sorted by salary (smallest first) in a neatly formatted table. The output for the data shown above would be Fred Smith Ann Simpson Jim Brown

£28000 £31000 £33000

CSEE Sociology CSEE

You may assume that no name occupies a total of more than 20 characters and no salary has more than 6 digits. The filename should be obtained from the user; if the file does not exist the program should terminate after displaying an appropriate message.

END OF SECTION B

END OF PAPER CE151-4-AU

[15%]...


Similar Free PDFs