Home » Display a random fact using a python module

Display a random fact using a python module

Randfacts is a Python module that generates random facts.

There are thousands of facts built in.

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

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