Skip to content
Related Articles

Related Articles

Randfacts library in Python
  • Last Updated : 23 Jan, 2021

In this article, we are going to learn about Randfacts python library that generates random facts. You can use randfacts.getFact() to return a random fun fact.

Installation:

pip install randfacts

Code for printing the random facts:

Python3




# code
import randfacts
  
  
x = randfacts.getFact()
print(x)

Output:



People in the United States eat 9 billion chickens and 150 million cattle, 

pigs and sheep annually, and we use around 26 million animals for research, 

95% of which are rodents, birds and fish.

getFacts Function: It is a function that accepts a boolean value. If we pass TRUE we will have a True fact and if we pass FALSE we will get a random Fun fact.

To produce a false funny statement

Python3




# code
import randfacts
  
  
x = randfacts.getFact(False)
print(x)

Output:

Despite assassination plots, an invasion and five decades of economic sanctions, 



Fidel Castro outlasted nine U.S. presidents in power, from Eisenhower to Clinton.

To produce a true statement

Python3




# code
import randfacts
  
  
x = randfacts.getFact(True)
print(x)

Output:

Anne Frank, Martin Luther King Jr. and Barbara Walters were all born in the same year.

To produce ten interesting facts simultaneously using the loop:

Python3




# code
import randfacts
  
  
for i in range(10):
    x = randfacts.getFact(True)
    print(x)

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :