Starting from:

$29.99

CSC401 Assignment 2 Solution


Reading
Read Chapter 4 and 7.3 in Introduction to Computing using Python: An Application Development Focus, Second Edition by Ljubomir Perković.
Logistics
You need to do this assignment on a computer which has Python 3 installed on it. Python 3.8.5 download page can be found here.
A submission that includes code which does not run will not get any points for the part unless specifically documented reason of the error.
Assignment
1. Decisions, loops and stings (10pt)
Write a function that takes a list of strings as a parameter, say ['Antheil', 'SaintSaens', 'Price', 'Easdale', 'Nielsen'], whose last letter is the same as the first letter. (so Saint-Saens, Easdale and Nielsen should get listed, but not the others.) Note that the case of the letters should not matter. You will do a case insensitive comparison this time.




Strings (30pt)
a. (15pt) Write a function password_check(oldpwd, newpwd) that has two parameters, newpwd and oldpwd, which represent a new password and the old password. The function accepts the new password (returns True) if the newpwd fulfills all of the following conditions:
i. newpwd is different from oldpwd
ii. newpwd is at least 8 letters long
iii. newpwd contains some character which is not a letter (i.e. a number, or some special character). Hint: research the string type using help(str) to look for appropriate tools to do this.
If the new password fails the check, your function should return False.

b. (15pt) Implement a function wordOccurCounter(sentence, word) that has two parameters: sentence representing a sentence and word representing a word, and returns the number of times the word appears in the sentence. Please make sure to remove any punctuation from the "sentence" before counting words. For the purposes of this question, punctuation is restricted to a comma and a period. If either parameter string is empty the function should return 0. It should not be case sensitive when counting words,
i.e., capitalization of the word of the sentence should not make any difference. The function should not consider substrings when checking for the word. The following shows several examples of how the function could be used:

Print (20pt)
We have seen a multiplication chart like this

It could be 1x to 10x, but sometimes we can stretch it to 12x or more.
Implement a function multLine(line, numCount) that takes two parameters: first one indicating which line to print and second one deciding how many numbers to multiply. First print the line number then followed by multiples.





File I/O (40pt)
a. (20pt) Write a function numVowels(filename) that has one parameter filename representing a file name and returns the number of vowels (case insensitive) that appear in the file. For the purposes of this question a vowel is one of a, e, i, o, or u.


b. (20pt) Implement the function merge(file1, file2) that takes two strings as parameters: both represent filenames. The function will merge the two files. Content in the second file(file2) will be appended to the end of the first file(file1). Below is the simple example of how it works.
Before merge:

Call merge() function
>>> merge('file1.txt', 'file2.txt')
After merge:


Submission
Submit the assignment using Assignment 2 folder. Submit only a single python file using your name as file name (e.g. Jay_Tang_Assign_2.py).

More products