Question: using python numpy First function - read _ words ( filename ) Create a function that when passed a CSV filename ( with headers )

using python numpy
First function - read_words( filename)
Create a function that when passed a CSV filename (with headers), will check if the file exists, and then read its contents into a NumPy array. Return this array.
If the file doesn't exist return an empty array.
Second function - read_story( filename )
Create a function that, when passed the name of your basestory#.txt file, will check if the file exists, and then read its contents into a list of strings. Return this list
If the file doesn't exist return an empty list.
You will have a main code cell that will continually run until the user chooses to exit (think while loop)
The program will call a menu function that will present the user with 3 options:
Create random storyPrint the mad lib arraysExit
Reprint the menu after each function call
After the menu() function returns the selection, call the appropriate function
Functions
menu() print a menu of options when you start the program and return the selection. Make sure your input is valid. If not, ask again
read_words( filename ) will read a CSV file of words passed to it and return a NumPy array of all the words. This was created using AI in Part 1
read_story( filename ) will read a text file passed to it and return a list of strings from the file. This was created using AI in Part 1
print_words( words_array ) will print the words from the madlib NumPy array by category
create_story( words_array, storytext, outputfile ) will create the story using the base story and the mad lib parts. It will print the story to the screen line by line. Finally, it will append the story text to the file mystory.txt
From a created random story basestory.txt, and madlibwords.csv file
Print the mad lib arrays
use np.random.choice( array ) to randomly pick a value from a 1D array
to use the time library and time.sleep( seconds ) to delay printing
to use string.replace( value_to_find, value_to_replace_with ) to search through your story text and substitute your mad lib values,
Add a menu option to make your program print the story as if it were being written in front of us - letter by letter. Make sure this is not too slow. Implement this functionality

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 Programming Questions!