Question: Python You will require to read data from a file and perform operations on the data Create a file named csc101.py 1. Using the open

Python

You will require to read data from a file and perform operations on the data

Create a file named csc101.py

1. Using the open function in python, read the file info.txt. You MUST use try/except for error handling. If the file is not found, show a message that says "File not found"

2. Read the data from the file using readlines() method. Make sure to close the file after reading it

3. Take the data and place it into a list. The data in the list will look like the list below

['CSC 101 ', 'BMCC ', ' ', 'Good luck on your project! ', ' ', 'name ', ' ', 'email ', 'dog ', 'deer ', 'lion ', 'bear ', ' ', 'horse ', 'cow ', 'leopard ', 'whale ']

4. Create a function called remove_new_line_char_from_list(list) that removes all the items from the list. You can use the pop() method with looping. https://www.w3schools.com/python/ref_list_pop.asp TAB Correctly i = 0 ls = your list while i

5. Create a function called remove_new_line_char_from_string(list) that loops over the list and remove the new line character ( ) from each string

6. Create a function called modify_name that finds(list, your_name) "name" and replace it with your full name

All functions you were asked to create must take the list as an argument. These functions do not have a return value. Your functions will modify the list of items. You can always print the list to ensure your code modified the list in each function.

NOTES:I pretty much finished structuring the entire project but i can't seem to get it to run through the functions, i'm also using replt so if it's can be edited through there that would be great if not it's fine https://repl.it/repls/ShyWildCopyleft . here the information that's on the info.txt file

-----------------------------------------------------info.txt---------------------------------------------------------------------------

CSC 101

BMCC

Good luck on your project!

name

email

dog

deer

lion

bear

horse

cow

leopard

whale

------------------------------------------------------end of info on info.txt------------------------------------------------------------------

def remove_new_line_char_from_list(list):

i = 0

ls = list

while i

if ls[i] == ' ':

ls.pop(i)

i += 1

def remove_new_line_char_string(list):

i=0

ls=list

for items in ls:

#test=''

if items[i]==' ':

ls.pop(i)

i+=1

def modify_name(list, your_name):

new_name=''

for items in list:

if items=='name':

new_name = new_name + your_name

new_list=''

try:

f = open("info.txt", "r")

print(f.readlines())

for items in f:

new_list=new_list+f

f.close()

except:

print("File not found")

# i commented these out because i was testing them one by one and i couldn't get it to function properly, all i'm getting in return is the list content and None

#print (remove_new_line_char_from_list(new_list))

#print(remove_new_line_char_string(new_list))

#print(modify_name(new_list,'Micheal'))

print(new_list)

Python You will require to read data from a file and perform

['CSC 101 ', 'BMCC ', ' ', 'Good luck on your project! ', ' ', 'name ', 'email ', 'dog ', 'deer ', 'lion ', 'bear ', ' ', 'horse ', 'cow ', 'Teopar d ', 'whale'] None

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!