Question

Define a function called positivity generator. The function should take user input of a sentence, and...

  1. Define a function called positivity generator. The function should take user input of a sentence, and find the first appearance of the substring 'not' and 'bad' from the user input. If 'not' appears before the 'bad', the function should replace the whole 'not'...'bad' substring with 'good'. Return the resulting string. Note your function should be able to handle user input with difference cases.

Example:

Input = 'The ice cream is not bad!'

Output = 'The ice cream is good!"

Input = 'The ice cream is not that bad!'

Output = 'The ice cream is good!"

Input = 'The ice cream is NOT bad at all!'

Output = 'The ice cream is good at all!"

Input = 'The ice cream is not strawberry flavor, but the vanilla flavor is also not bad!'

Output = 'The ice cream is good!"

Homework Answers

Answer #1

def positiveGenerator(s):

    temp = s.upper()

    n = temp.find("NOT")

    b = temp.find("BAD")

    if n < b:

        answer = s[:n] + "good" + s[(b+3):]

        return answer

    else:

        return s

    # print(n, b)

s = input()

print(positiveGenerator(s))

output:

Know the answer?
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
Similar Questions
This is C. Please write it C. 1) Prompt the user to enter a string of...
This is C. Please write it C. 1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
**please write code with function definition taking in input and use given variable names** for e.g....
**please write code with function definition taking in input and use given variable names** for e.g. List matchNames(List inputNames, List secRecords) Java or Python Please Note:    * The function is expected to return a STRING_ARRAY.      * The function accepts following parameters:      *  1. STRING_ARRAY inputNames      *  2. STRING_ARRAY secRecords      */ Problem Statement Introduction Imagine you are helping the Security Exchange Commission (SEC) respond to anonymous tips. One of the biggest problems the team faces is handling the transcription of the companies reported...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT