Create a Quote Generator in PythonTask: User enters a hash tag and based on that tag, the Python program must be able to generate quotes one after the other. If the program isn't able to find any quote with the given tag, it has to print "Quote with given hash tag isn't found". Solution: We need to use a data set for this task. The data set must contain quotes and tags that can be associated with each quote. The program can then search the data set for the user specified tag and if it finds any quote, it can print the quote. We can find a lot of data sets already in the internet uploaded by developers across various websites like github, kaggle, etc. In this tutorial, we are using a dataset from kaggle. Here is how, you can find it:
A JSON file:JSON stands for "JavaScript Object Notation". It is a language-independent standard data format. It is used in various applications of data especially for data interchange between web applications and servers. It was derived from JavaScript and hence the name.It uses human-readable text to store and transmit data. The data is arranged in the form of attribute-value pairs. A .json file can be imported into excel for a structured tale format. Here are two quotes from the quotes dataset: Now, if we try to understand the underlying table structure of the file:
Now, we'll write a program to read the json file, filter it with quotes with the user specified tag, sort it according to maximum popularity and then print the most popular quotes one after the other: Code: Output: Enter a tag:happiness Popularity: 0.15566615566615566 Quote: Don't cry because it's over, smile because it happened. Next(Y/N):Y Popularity: 0.025575025575025574 Quote: Love is that condition in which the happiness of another person is essential to your own. Next(Y/N):Y Popularity: 0.01855001855001855 Quote: Time you enjoy wasting is not wasted time. Next(Y/N):Y Popularity: 0.01366001366001366 Quote: It's so hard to forget pain, but it's even harder to remember sweetness. We have no scar to show for happiness. We learn so little from peace. Next(Y/N):N Explanation:
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week