Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

['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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions

Question

Networking is a two-way street. Discuss this statement.

Answered: 1 week ago