Question

1. Create a Python Class Paragraph(), which can be initialized with a string that the user...

1. Create a Python Class Paragraph(), which can be initialized with a string that the user enters (or from whatever source we so choose).

So, we can create a Paragraph by:

userProse1 = Paragraph(input())

2. Write a Python method (choose a good name!) to return the count the number of words in a Paragraph object.

So, an input of Paragraph ("Mary had a little lamb, the little lamb belongs to Mary") will return 11.

3. Write a Python Method to return a list that has the distinct words in that  Paragraph .

For example. If the Paragraph just had a bunch of words of different colors such as  Paragraph ("pink black black white pink pink red red black, black, white white white, pink pink, red pink red pink pink pink black pink")

This method would return:
[‘pink', 'black', 'white', 'red']

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

#source code:

class Paragraph():
   def __init__(self,user):
       self.user=user
       print(self.user)
   def words_count(self):
       count=1
       for i in range(len(self.user)):
           if(self.user[i]==" "):
               count=count+1
       return count
   def distinict(self):
       dist=[]
       sub=self.user.split(" ")
       for x in sub:
           if x not in dist:
               dist.append(x)
       new=[]
       main=[]
       for i in range(len(dist)):
           check=len(dist[i])
           if(dist[i][check-1]=="," or dist[i][check-1]=="."):
               new.append(dist[i][0:check-1])
           else:
               new.append(dist[i])
       for x in new:
           if x not in main:
               main.append(x)
       return main
userProse1=Paragraph(input("Enter Paragraph:"))
print("Words count:",userProse1.words_count())
userProse2=Paragraph(input("Enter Paragraph:"))
print("distinict list:",userProse2.distinict())

#if you have any doubts comment below...

Add a comment
Know the answer?
Add Answer to:
1. Create a Python Class Paragraph(), which can be initialized with a string that the user...
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
  • Create a function called countWords(string): That will count words in given string by user. Use Python...

    Create a function called countWords(string): That will count words in given string by user. Use Python 3.6 If user inputs "Mary had a little lamb" it should return 5

  • Using python Question 13 (20 points) Write a function named Linestats that finds the number of...

    Using python Question 13 (20 points) Write a function named Linestats that finds the number of consonant and vowel letters on each line of a file and writes those statistics to a corresponding line of a new file, separated by a space. Definitions: A vowel letter is one of a, e, i, o, u, along with the corresponding uppercase letters..A consonant letter is not a vowel letter. The function linestats takes two parameters: 1. inFile, a string, the name of...

  • 1. Extending the answer from Python HW #7 for question #1, write the following python code...

    1. Extending the answer from Python HW #7 for question #1, write the following python code to expand on the Car class. Include the python code you developed when answering HW #7. Add class “getter” methods to return the values for model, color, and MPG Add class “setter” methods to change the existing values for model, color, and MPG. The value to be used in the methods will be passed as an input argument. Add class method that will calculate...

  • File Processing and Arrays Create a class named FilesAndArrays. Download the sidewalk.txt file so it is...

    File Processing and Arrays Create a class named FilesAndArrays. Download the sidewalk.txt file so it is in your project’s root folder. Write a static method named findFirstMatch that accepts as its parameters a Scanner for an input file and an array of Strings keywords representing a list of keywords in a search. Your method will read lines from its input Scanner and should return the line number of the first line in the file that contains one or more words...

  • Questions 1. How to create a comment in python? 2. The way to obtain user input...

    Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....

  • Python Code Question# 1 General Instructions Create a class called LawnService that takes in the length...

    Python Code Question# 1 General Instructions Create a class called LawnService that takes in the length and width of a yard, along with the current state of the yard. The currect state can be: poor, acceptable or great. Within this class include a constructor that will assign these values to attributes. Additionally create three methods that will be named and do the following: *DetermineApplication: This method will focus on the lawn status attribute. If the status is poor, the lawn...

  • Python Project

    AssignmentBitmap files map three 8-bit (1-byte) color channels per pixel. A pixel is a light-emitting "dot" on your screen. Whenever you buy a new monitor, you will see the pixel configuration by its width and height, such as 1920 x 1080 (1080p) or 3840x2160 (4K). This tells us that we have 1080 rows (height), and each row has 1920 (width) pixels.The bitmap file format is fairly straight forward where we tell the file what our width and height are. When...

  • ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the...

    ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the file is directly executed Hint: def main(): pass if __name__ == '__main__': main() 2. Your programs will use a file called scores.txt to store a bunch of user-provided numbers. These can be int or float but their values must be between 0 and 100. Inside the main function, display the current list of numbers to the user and ask if they want to update...

  • Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type...

    Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type of credit card he/she would like to find the checksum for. 2. Based on the user's choice of credit card, asks the user for the n digits of the credit card. [Get the input as a string; it's easier to work with the string, so don't convert to an integer.] 3. Using the user's input of the n digits, finds the last digit of...

  • Python GPA calculator: Assume the user has a bunch of courses they took, and need to...

    Python GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....

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