Question

In python your goal is to ask the user for Nouns, Verbs, Adjectives… and fit them...

In python your goal is to ask the user for Nouns, Verbs, Adjectives… and fit them in the text where they appear. Each word should be unique.

e.g. ask the user for a Noun and replace the first appearance of [Noun] in the text below by the user input.

Technical requirements:

    Save the following text to a file.

    Open the file and replace all the words in between [] by user inputs using .format(). (You can manually modify the text below to fit the requirements for .format()).

    Use a try except block(s) to validate all the user input. Save the new text to a file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the solution to above problem in python. Please see the code screenshot for the indentation help and please read the code comments for more information

PYTHON CODE

text=""
userNoun=[]
userVerb=[]
userAdj=[]
nounCount=0
verbCount=0
adjCount=0
with open('input.txt','r') as File:
for line in File:
for word in line.split(' '):
if(word == '[Noun]'):
nounCount=nounCount+1
elif(word == '[Verb]'):
verbCount=verbCount+1
elif(word == '[Adjective]'):
adjCount= adjCount+1
print(word+ " "),
File.close();

#user input noun
print("\nEnter " + str(nounCount) + " Nouns: ")
try:
for i in range(0,nounCount):
word= str(raw_input("Noun "+ str(i+1)+": "))
userNoun.append(word)
except:
print("An Exception Occured")
#user input verb
print("Enter " + str(verbCount) + " Verbs: ")
try:
for i in range(0,verbCount):
userVerb.append(str(raw_input("Verb "+ str(i+1)+": ")))
except:
print("An Exception Occured");
#user input adjective
print("Enter " + str(adjCount) + " Adjectives: ")
try:
for i in range(0,adjCount):
userAdj.append(str(raw_input("Adjective "+ str(i+1)+": ")))
except:
print("An Exception Occured");

nounCount=0
verbCount=0
adjCount=0
text=""
#modifying the text
with open('input.txt','r') as File:
for line in File:
for word in line.split():
if(word == '[Noun]'):
word=userNoun[nounCount]
nounCount=nounCount+1
elif(word == '[Verb]'):
word=userVerb[verbCount]
verbCount = verbCount+1
elif(word == '[Adjective]'):
word=userAdj[adjCount]
adjCount= adjCount+1
text=text+ word+ " "
text=text + "\n"
#printing modified text
print("MODIFIED TEXT")
print(text)
File.close()
#writing modified text to a file
File = open('input.txt',"w")
File.write(text)
File.close();


SCREENSHOT OF CODE

OUTPUT SCREENSHOT

INPUT FILE SCREENSHOT

OUTPUT FILE SCREENSHOT

Add a comment
Know the answer?
Add Answer to:
In python your goal is to ask the user for Nouns, Verbs, Adjectives… and fit them...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry...

    Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem​: Each entry in the dictionary is a pair: (word, meaning). Word is a one-word string, meaning can be a string of one or more words (it’s your choice of implementation, you can restrict the meaning to one-word strings). The dictionary is case-insensitive. It means “Book”, “BOOK”, “book” are all the same . Your dictionary application must provide its operations through the following menu (make sure that...

  • This needs to be written in Python. I'm writing this but I'd love to see how...

    This needs to be written in Python. I'm writing this but I'd love to see how others would do it. I have idea to make a program to keep track of reading. Set goal per day. Input minutes per day & book read. Could accumulate for whole month. Input daily, but you can input it all at the end of the week if you want. I want the user to be prompted to enter a numerical value and book for...

  • Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user...

    Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user login system. Your code should do the following: 3, create-user_name() #use this function to create the user name 1.Create your user database called "UD.txt", this should be in CSV format 4, write-file() #user this function to save the user name and password into "UD.txt" Deliverables: Sample: the data you saved...

  • PYTHON Build a regular expressions based on informal specifications to match specified patterns. Use a compiled...

    PYTHON Build a regular expressions based on informal specifications to match specified patterns. Use a compiled regular expression in a Python program where appropriate. Use Python's text processing str methods to generate a string format converter. create a date format converter. Your program will convert a date in the format “mm/dd/yyyy” to the format “month day, year”. Specify the required input format: mm/dd/yyyy Use a regular expression to validate the user input date format. If the format is incorrect raise...

  • JAVA Primitive Editor The primary goal of the assignment is to develop a Java based primitive...

    JAVA Primitive Editor The primary goal of the assignment is to develop a Java based primitive editor. We all know what an editor of a text file is. Notepad, Wordpad, TextWrangler, Pages, and Word are all text editors, where you can type text, correct the text in various places by moving the cursor to the right place and making changes. The biggest advantage with these editors is that you can see the text and visually see the edits you are...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • Python Programming Topics: list, file input/output You will write a program that allows the user to...

    Python Programming Topics: list, file input/output You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing...

  • I am writing a Python program to serve as a fitness tracker. I would love some...

    I am writing a Python program to serve as a fitness tracker. I would love some input as to how you would code this. I've included what I want this program to accomplish, what I will keep track of, and below all of that I have posted the assignment guidelines. Any suggestions on how to make this better/ more efficient would be welcome! I'm thinking of making a weekly tracker that takes input per day, and outputs at the end...

  • Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that...

    Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...

  • Write a program which will Ask the user a series of questions using the Scanner object Based on t...

    Write a program which will Ask the user a series of questions using the Scanner object Based on the input, draw a grid of star figures on the DrawingPanel You program should ask your user: . What R, G & B values to create a color to draw the figure? How many stars across should the fgure be? How many stars tall should the figure be? Note that your program does not need to error check the users responses Your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT