1 Carleton University School of Computer Science Comp 1005- Assignment 2 Due Date: Check the schedule in the course outline Submission Guidelines: Check the assignment guidelines and recommendations...

1 answer below »
attached in pdf


1 Carleton University School of Computer Science Comp 1005- Assignment 2 Due Date: Check the schedule in the course outline Submission Guidelines: Check the assignment guidelines and recommendations in the course outline **** Assignment name: should be A2-your student number*********** Notes: It is essential that you use the built-in, default, archiving program to create this zip folder. If we cannot easily open your zip file and extract the python files from them, we cannot grade your assignment. Other file formats, such as rar, 7zip, etc., will not be accepted. Windows: Highlight (select with ctrl-click) all of your files for submission. Right-click and select “Send to” and then “Compressed (zipped) folder”. Change the name of the new folder “A1-your student number.zip”. MacOS: Highlight (select with shift-click) all of your files for submission in Finder. Right-click on one of the files and select “compress N items…” where N is the number of files you have selected. Rename the “Archive.zip” file “A1-your student number.zip”. Linux: use the zip program. After submitting your A1-your student number.zip file to cuLearn, be sure that you download it and then unzip it to be certain that what you have submitted is what you wanted to submit. This also checks that your zip file is not corrupted and can be unzipped. Coding Guidelines [ ignoring these guidelines will result in marks deductions even if your program is syntactically and logically correct]: 1- Comment your code where necessary to improve the readability of your program. 2- Use the try-except to prevent erroneous user inputs 3- Define and use functions for performing tasks within your program. 2 The assignment is composed of two questions that must be solved correctly in order to achieve a full mark. Question1 [60 marks]: Python supports the use of data files. In Python there are different modes that allow a user to create, write, append, read, and update date files. Table 1 shows the various file modes in Python. Write a Python program that creates a user interface (menu) which allows the user to choose an option from the followings menu then perform the required task accordingly. The menu should have the following options: 1. Writing text to a file: Write the 6 to 8 lines of text into a file named “assignment2.txt”. You can use special characters such as \n to separate lines. 2. Read Data from a file: reads (retrieve) the data from the file “assignment2.txt” and print it on the screen in the same format as it was input (i.e., same number of lines). Make sure Table 1: Python File modes Mode Description 'r' Opens a file for reading. 'w' Open a file for writing. If file does not exist, it creates a new file. If file exists it truncates the file. 'a' Open a file in append mode. If file does not exist, it creates a new file. '+' Open a file for reading and writing (updating) 3 the file already exist and it is not empty, otherwise warn the user that the file doesn’t exist or it is empty. 3. Search for string and calculate the number of occurrences: you should search for a certain word that you specify from the text. If the word doesn’t exist, it should report to the user “the word doesn’t exist” and asks the user to enter another word. 4. Quit the program: allows the user to quit the execution of the program. Question2 [40 marks]: Write a Python program that allows the user to print the following shape of stars according to the following algorithm 1- Move 69 spaces horizontally and print 1 star. 2- Move down, leaving a space line, and double print the number of the stars in the previous line. 3- Perform this process until you print 16 stars in the last line. 4- The left indentation (spaces to the left) of the first star in each line is (70- number of the stars in that line). For instance, the left indentation for line 3 in which it has 4 stars is (70- 4 = 66 spaces). You should use a mathematical formula that compute and print the stars in each line. Also, you should use a mathematical formula the compute the left indentation. * ** **** ******** ****************
Answered Same DayOct 13, 2021

Answer To: 1 Carleton University School of Computer Science Comp 1005- Assignment 2 Due Date: Check the...

Arun Shankar answered on Oct 14 2021
148 Votes
__MACOSX/._Python Assignment 2
Python Assignment 2/assignment2.txt
make america great again
india
is awesome
this is fine
make america great again
testing
hello how are you
we are good
__MACOSX/Python Assignment 2/._assignment2.txt
Python Assignment 2/.DS_Store
__MACOSX/Python Assignment 2/._.DS_Store
Python Assignment 2/program_02.py
def main():
stars = 1
while(stars <= 16):
s = ' ' * (70 - stars)
print(s,end = "")
s = '*' * stars
print(s)
stars *= 2
main()
__MACOSX/Python Assignment 2/._program_02.py
Python Assignment...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here