End_of_Semester_2_2019_COMP1005_490

.pdf

School

Curtin University *

*We aren’t endorsed by this school

Course

2020

Subject

Electrical Engineering

Date

Dec 6, 2023

Type

pdf

Pages

18

Uploaded by ColonelWater15869

Report
End of Semester 2, 2019 COMP1005 Fundamentals of Programming Examination Cover Sheet School of Electrical Engineering, Computing and Mathematical Sciences EXAMINATION End of Semester 2, 2019 COMP1005 Fundamentals of Programming This paper is for Bentley Campus students This is a CLOSED BOOK examination Examination paper IS NOT to be released to student Examination Duration 2 hours Reading Time 10 minutes Students may write notes in the margins of the exam paper during reading time Total Marks 120 Supplied by the University None Supplied by the Student Materials None Calculator No calculators are permitted in this exam Instructions to Students Answer all questions in the space provided in the question paper. For Examiner Use Only Q Mark 1 2 3 4 5 Total ________ Venue ____________________ Student Number |__|__|__|__|__|__|__|__| Family Name _____________________ First Name _____________________
End of Semester 2, 2019 COMP1005 Fundamentals of Programming Page 1 of 17 QUESTION ONE (Total: 30 marks): Datatypes and Data Handling assorted.py import random biscuits = [] # Add biscuits to packet biscuits.extend(['Monte Carlo']*7) biscuits.extend(['Shortbread Cream']*7) biscuits.extend(['Delta Cream']*6) biscuits.extend(['Orange Slice']*6) biscuits.extend(['Kingston']*5) print('\nASSORTED CREAMS\n') choice = random.randint(0,len(biscuits)-1) print('Your biscuit is : ', biscuits[choice]) del biscuits[choice] Modify/rewrite the code above to: a) (2 marks) . Loop through to ask the user if they want another biscuit, and exit the loop if they don’t. b) (2 marks) . Increase the initial number of Kingstons to 7 and reduce the Delta Creams and Orange Slices to 5. c) (4 marks) . Include a function printBiscuits() to print out the number of each type of biscuit remaining in the packet. (Hint: you can use a dictionary to store the counts) d) (3 marks). Include a function, addBiscuits(btype, bcount), to add bcount biscuits of type btype to the jar. For example addBiscuits("Kingston", 5) would add 5 Kingston biscuits. e) (3 marks). Within the loop, ask the user if they want to add biscuits, then ask for the type and number, and call addBiscuits(btype, bcount) to add the biscuits. (use the back of the page if you need more space) QUESTION ONE continues on the next page…
End of Semester 2, 2019 COMP1005 Fundamentals of Programming Page 2 of 17 QUESTION ONE (continued) wordfreq.py punctuation = '~!@#$%^&*()_+{}|:"<>?`=[]\\;\',./' filename = 'grimm.txt' book = open(filename).read() bookNoPunct = book.translate(str.maketrans('','',punctuation)) words = bookNoPunct.split() wordfreq = {} for word in words: if word not in wordfreq: wordfreq[word] = 0 wordfreq[word] += 1 Modify the code above to .... f) (4 marks) . Print out the most and least frequent words. QUESTION ONE continues on the next page…
End of Semester 2, 2019 COMP1005 Fundamentals of Programming Page 3 of 17 QUESTION ONE (continued) g) (2 marks) . What would the output of the program regtest.py be if it was given the input file addresses.txt (below). regtest.py import re addressRegex = re.compile(r'''( (\d{3}) \s (\w+) )''', re.VERBOSE) fileobj = open('addresses.txt') data = fileobj.readlines() for address in data: address = address.strip() mo = addressRegex.search(address) if mo: print('Found: ' + mo.group()) addresses.txt 30 Python St, Jupyter, 2001, VIC 300 Python St, Jupyter Springs, 2010, WA 3000 Python Meander, Jupyter Notebook, 2001, ACT 3 Python St, Jupyter, 2010, QLD 30 Python Street, Jupyter, 2001, NT 30a Python Street, Jupyter, 2001, NSW 3 Python Package Index, Jupyter, 2010, TAS Answer: h) (4 marks) . Provide code for changes that would be required for regtest.py to completely and specifically match each part of the address (number, street, suburb, postcode and state) as given in the input file. QUESTION ONE continues on the next page…
End of Semester 2, 2019 COMP1005 Fundamentals of Programming Page 4 of 17 QUESTION ONE (continued) i) (6 marks). Give code, using list comprehensions, to create the following: i. Create a list “stringlist” that takes integer numbers in templist, and converts each to a string: e.g. templist = [74, 34, 284, 290] ii. Create a new list "pluscodes", containing each phone number in numlist with the "08" area code prepended (put at the start): e.g. numlist = [‘92661000', '92662000', '92663000'] iii. Create a new list called "bundles", which contains the numbers from 0 to 200, increasing by ten each time. e.g. bundles = [0, 10, 20 … 180, 190, 200] QUESTION TWO is on the next page
End of Semester 2, 2019 COMP1005 Fundamentals of Programming Page 5 of 17 QUESTION TWO (Total: 25 marks): Arrays, Grids and Plotting a) (6 marks) . The following code creates four arrays: t, t2, t3 and t4. Modify the code to: plot t as black circles plot t2 as blue squares plot t3 as green triangles plot t4 as red dashes plot them as 2x2 subplots save the resulting plot as "examSubplots.png" multilineplot.py import numpy as np import matplotlib.pyplot as plt t = np.arange(0., 5., 0.2) t2 = t**2 t3 = t**3 t4 = t**4 #plt.plot(t, t, t, t2, t, t3, t, t4) #plt.show() QUESTION TWO continues on the next page…
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help