Create a Quote Generator in Python
Task: 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".
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:
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:
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
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