0% found this document useful (0 votes)
120 views8 pages

MCD4710 Week3 Sample Test Sol

This document provides a sample test for an introduction to algorithms and programming mid-trimester exam. It consists of 9 multiple choice and short answer questions worth a total of 24 marks. The document outlines the structure of the test, authorized and prohibited materials, and instructions to candidates. It provides sample questions that require writing Python code or explaining concepts related to algorithms.

Uploaded by

Vionnie Tan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views8 pages

MCD4710 Week3 Sample Test Sol

This document provides a sample test for an introduction to algorithms and programming mid-trimester exam. It consists of 9 multiple choice and short answer questions worth a total of 24 marks. The document outlines the structure of the test, authorized and prohibited materials, and instructions to candidates. It provides sample questions that require writing Python code or explaining concepts related to algorithms.

Uploaded by

Vionnie Tan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

MCD4710: Introduction to Algorithms and

Programming Mid-Trimester Test 1


Sample Test
Reading time: 10 minutes
SOLUTIONS
Writing time: 45 minutes

Structure of Test
Section Number of Questions Total Possible Actual Marks
to be answered Marks
Output of simple Python code

Short Answer Questions

Total marks 24

During a test, you must not have in your possession a book, notes, paper, calculator, pencil case, mobile phone
or other material/item which has not been authorised for the test or specifically permitted as noted below. Any
material or item on your desk, chair or person will be deemed to be in your possession. You are reminded that
possession of unauthorised materials in a test is a discipline offence under Monash College regulations.

AUTHORISED MATERIALS

SCIENTIFIC CALCULATORS (w/ APPROVED STICKER) NO  YES


OPEN BOOK NO  YES
SPECIFICALLY PERMITTED ITEMS NO  YES
if yes, items permitted are:

INSTRUCTIONS TO CANDIDATES

 Show all working - diagrams are a valuable part of working and should be large enough, and
clearly labelled. Marks may be lost if working is not included.
 Write the final answer in the space provided.
 Do not use pencil.
 Write clearly. Marks cannot be given if your handwriting cannot be read.

Candidates must complete this section

STUDENT ID __ __ __ __ __ __ __ __ TUTOR’S NAME __ __ __ __ __ __ __

THIS ENTIRE TEST PAPER MUST BE HANDED IN AT THE END OF THE TEST.
DO NOT OPEN THIS BOOKLET UNTIL INSTRUCTED TO DO SO.
Important Information
All Python code you write for this test must satisfy the following requirements:
ˆ Syntax should satisfy Python 3 requirements
ˆ Use syntax, modules, structures and constructs presented in lectures.
ˆ Avoid inbuilt python functions or libraries that make your work signicantly easier to
write (for example the inbuilt min method when you are asked to nd the smallest
item in a list)
Write down any assumptions you make.

0
Question 1: [1 marks]
What will be printed by the following
aList = [1 ,2 ,3]
a L i s t *= 2
print ( a L i s t )

[1,2,3,1,2,3]

Question 2: [1 marks]
What will be printed by the following
b S t r i n g = " abc123 "
print ( b S t r i n g [ 1 : 4 ] )

bc1

Question 3: [1 marks]
What will be printed by the following
cList = [4 ,2 ,0]
for item in c L i s t :
print ( str ( item ) * item )

4444
22

Question 4: [2 marks]
What will be printed by the following
d L i s t = [ " apple " , "banana" , " orange " , " k i w i f r u i t " ]
e L i s t = [ "APPLE" , "ORANGE" ]
for d in d L i s t :
i f d . upper ( ) in e L i s t :
print ( d )

5
apple
orange

0
Question 5: [1 marks]
What will be printed by the following
def fFunc ( f S t r i n g ) :
return f S t r i n g+f S t r i n g [ : : − 1 ]
print ( fFunc ( " one " ) )

oneeno

Question 6: [2 marks]
What will be printed by the following
g L i s t = [ "a" , "b" , False , 3 ]
h L i s t = [ 3 , True , "b" , "A" ]
for i in range ( len ( g L i s t ) ) :
i f not g L i s t [ i ]== h L i s t [ − i − 1]:
print ( str ( i )+" : "+str ( g L i s t [ i ] ) )

0:a
2:False

3
Question 7: [6 marks]
Consider the task of unlocking your front door and entering your house. Is this an
algorithm? Explain why/why not. Ensure you refer to each of the attributes of an
algorithm individually.

students should relate their answer to the following:

ˆ sequence - this task would be structured with each step in sequence. First you
find the key THEN you put it into the lock, etc.
ˆ Terminates - the task terminates as the key turns only so far before unlocking
ˆ Precise - unambiguous - this will depend on how the algorithm is written (ex. do
you turn clockwise or counter-clockwise?). It's possible to phrase this in a way
which is de˝nite.
ˆ Basic - sufficiently simple - again this depends on how it is written but it is
possible. You may need to specify precise angles to rotate the key by but it's
possible to do
ˆ input - one could argue that the key is the input into this task, fortunately
inputs are not required to be an algorithm
ˆ output - one could make an argument about the output of this task, they could
argue that the output is an unlocked door or equally they could argue that this
task is a procedure not an algorithm as there isn't a result passed on.

each point above is worth 1 mark. Students may answer dierently and are awarded
marks if their answer makes sense. They must still address each point however (ex.
they may believe it non-nite, if their argument makes sense they would get the
marks for niteness)

6
Question 8: [5 marks]
For this task, you should produce a python program to solve the following problem:
You have a string of letters (unique and lower case) and wish to determine how out of
order it is. For each letter, determine how many letters after this should occur before it.
You should print the sum of these counts for each letter.
For example, given the strings "abcdef", "zyda", and "afcbd", your program should
output:

0
6
4

"abcdef" -> "a" has nothing smaller than it to the right, the same is true of "b", "c",
"d", "e". "f" is on the far right so has nothing to the right of it
"zyda" -> 3+2+1+0 = 6 ("y","d" and "a" are all less than "z", "d" and "a" are less
than "y", etc.)
"afcbd" -> 0+3+1+0+0 = 4 ("c","b","d" are less than "f" and "b" is less than "c")

You may assume the string to consider is dened in a variable called inputString

count=0
for l e t P o s in range ( len ( i n p u t S t r i n g ) ) :
l e t t e r = inputString [ letPos ]
for o t h e r L e t t e r in i n p u t S t r i n g [ l e t P o s + 1 : ] :
if otherLetter < l e t t e r :
count+=1
print ( count )

ˆ 1 mark for considering each letter


ˆ 1 mark for consider letter to the right of it
ˆ 1 mark for checking if second letter < rst
ˆ 1 mark for updating count
ˆ 1 mark for initialising and displaying count

5
Question 9: [5 marks]
Write up a python program which takes as input from the user a positive integer and
determines the factors of that integer.
For instance:

please enter a number:35


1
5
7
35

baseNum = input ( " p l e a s e e n t e r a number" )


baseNum = int ( baseNum )

for p o s s i b l e in range ( 1 , baseNum+1):


i f baseNum%p o s s i b l e == 0 :
print ( p o s s i b l e )

ˆ 1 mark for input


ˆ 1 mark for converting to integer
ˆ 1 mark for looping
ˆ 1 mark for checking if given number is a factor
ˆ 1 mark for printing

You might also like