Sign In
Not register? Register Now!
Pages:
1 page/β‰ˆ275 words
Sources:
Check Instructions
Style:
APA
Subject:
IT & Computer Science
Type:
Coursework
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 6.48
Topic:

Python Programming

Coursework Instructions:

Open the pdf attatchment and solve answer these questions follow the instruction.

1 Introduction to Cognitive Science Final assignment Section 1: Python programming This section of the assignment asks you to answer some questions that primarily relate to Python programming, although they may also draw on your knowledge of other aspects of the course. This section of the final assignment is worth 12% of your grade for this course. The deadline for submitting this assignment is noon Thursday 17 December. Ensure that you read the linked web pages on ‘General Assessment Information’, including details on late penalties and late submission. That information can be found directly at: http://students.ppls.ed.ac.uk Instructions: • Answer BOTH questions below (Question 1 + Question 2) • Answer the questions neatly and clearly inside a single MS Word document. Ensure that the examiner can easily identify which question you answering and what your answer is. • Upload that the completed document to TurnItIn before the deadline Make sure to: • Include your exam number at the top (but not your name or student number) • Use a font size that is easily legible (precisely what size that is will depend on the font used, but for most fonts that will be at least 11 point) • Leave wide right and left margins (at least 2.5cm) • Use at least 1.5 line spacing • Number your pages consecutively Uploading to TurnItIn: • Go to Learn -> Assessment -> Assessment Submission • You will find a TurnItIn submission box for ‘Final assignment - Python section’ that will allow you to upload your completed document • Give your exam number (not your name or student number) as both the TurnItIn title and filename the file you submit (e.g. the file you submit should look something like ‘B34234.docx’) • Ensure you complete the associated ‘own work’ declaration alongside the submission box on Learn. It is essential that you complete this declaration. Please do not attempt to submit your answer in the form of a Python notebook. Questions? Please ask them on MS Teams ‘Python Chat’ channel! 2 QUESTION 1 The program below uses recursion to print a very long sentence clause by clause. The output is shown as well. def fun(c, x): if len(c)==1: return '\t'*x + c[0] else: return('\t'*x + c[0] + ' that \n' + fun(c[1:],x+1)) print(fun(['Martin said', 'Neil heard', 'Patrick believed', 'Mark thought', 'Jia explained', 'Hannah was late'], 0)) OUTPUT: Martin said that Neil heard that Patrick believed that Mark thought that Jia explained that Hannah was late (a) Rewrite the program with two additions to improve readability: (i) user-friendly comments and (ii) clearer variable/function names. You will leave the Python functionality the same (no changes to the Python structure or commands), but the new version you write with comments and new names will be easier to read. (b) Briefly relate recursion to the flexibility and productivity of natural language. Are infinitely long sentences possible and how does their (hypothetical) use inform debates about Nativism and Empiricism? 3 QUESTION 2 (a) There are three functions below. Consider each function and write out what it will output. Compare the output of the three functions: Do their outputs differ, and if so how? def function1(): word2 = "hello" word1 = word2 for i in range(3): print(i+1, word1) def function2(): word1 = "" word2 = "hello" for i in word2: word1 = word1 + i for n in range(4): print("{0} {1}".format(n, word1)) def function3(): word1 = "" word2 = "hello" for i in [1,2,3,4]: for n in word2: word1 = word1 + n print(i, word1) (b) Find the error(s) in the following Python code Numr = 4 second = numr+5 print(second) print(numr) (c) Find the error(s) in the following Python code x = range(10): for i in x: if x = 5: print “here’s the number 5!”

Coursework Sample Content Preview:

Assessment Section 1: Python
Name
Institutional Affiliation
Assessment Section 1: Python
Q#1
def fun(c, x): #defines the function with arguments
if len(c)==1:
return '\t'*x + c[0] # Returns the value of the length is equal to 1
else:
return('\t'*x + c[0] + ' that \n' + fun(c[1:],x+1)) #If not equal to 1 it will return additional string "that"
print(fun(['Martin said', 'Neil heard', 'Patrick believed',
'Mark thought', 'Jia explained', 'Hannah was late'], 0)) #Outputs
Martin said that
Neil heard that
Patrick believed that
Mark thought that
Jia explained that
Hannah was late
Recursiveness is used to describe a language with phrases or sentences, which can contain themselves such as a language with sentences within phrases or sentences within phrases or sentences (Lumen, , n.d). This increases the productivity and flexibility of natural language and their use inform about the empiricism and nativism in Python language. Compared to Java, Python enhances productivity since Java is largely a compiled language
Q#2
The three programs differ in their outputs as show below. While the first program begins at index , the second program begins at index 0. The thi...
Updated on
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:

πŸ‘€ Other Visitors are Viewing These APA Coursework Samples:

HIRE A WRITER FROM $11.95 / PAGE
ORDER WITH 15% DISCOUNT!