Home » Display a random fact using a python module

Display a random fact using a python module

Oracle Java Certification
Java SE 11 Programmer II [1Z0-816] Practice Tests
Java SE 11 Developer (Upgrade) [1Z0-817]
Java SE 11 Programmer I [1Z0-815] Practice Tests
1 Year Subscription
Spring Framework Basics Video Course

Randfacts is a Python module that generates random facts.

There are thousands of facts built in.

Table of Contents

Installation

pip install randfacts

 

Examples

import randfacts
fact = randfacts.get_fact()
print(fact)

When you run this you should see something like this, a random fact

The human brain cannot feel pain.

This package has a filter option to filter out potentially inappropriate facts. The filter is on by default. To disable the filter, you can just set the filter_enabled parameter to False.

import randfacts
fact = randfacts.get_fact()
print(fact)
filtered_fact = randfacts.get_fact(filter_enabled=False)
print(filtered_fact)

Running this I saw this

Medieval chastity belts are a myth. A great majority of examples now existing were made in the 18th and 19th centuries as jokes.
The catfish has over 27,000 taste buds.

If you want to access the list of facts directly, you can just import the safe_factsunsafe_facts, or all_facts lists from the randfacts module.

You may also like

1 comment

Create random fact app using tkinter - max python 10 June 2023 - 9:03 pm

[…] In a previous article we showed you how you get a  random fact using a library – http://www.maxpython.com/modules/display-a-random-fact-using-a-python-module.php […]

Reply

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More