Fun Facts

Write a program that chooses and displays a random fact from a 1-D Array. The program should have an array of facts. When the program is run, a fact should be chosen at random and displayed to the user.

Honey never spoils.
Octopuses have three hearts.
Welsh is one of the oldest living languages in Europe.
DECLARE facts INITIALLY ["Honey never spoils.", 
                         "Bananas are berries, but strawberries aren't.", 
                         "Welsh is one of the oldest living languages in Europe.", 
                         "Octopuses have three hearts."]

DECLARE factIndex INITIALLY 0

SET factIndex TO RANDOM_NUMBER BETWEEN 0 AND LENGTH(facts) - 1

SEND facts[factIndex] TO DISPLAY
import random

facts = [
    "Honey never spoils.",
    "Bananas are berries, but strawberries aren't.",
    "Welsh is one of the oldest living languages in Europe.",
    "Octopuses have three hearts.",
]

fact_to_display = random.randint(0, len(facts)-1)

print(facts[fact_to_display])
import random

# An array of facts - can be written in one line or spaced out to make it more readable
facts = [
    "Honey never spoils.",
    "Bananas are berries, but strawberries aren't.",
    "Welsh is one of the oldest living languages in Europe.",
    "Octopuses have three hearts.",
]

# Picking a number between 0 and the length of the facts array
# Use len(facts)-1 because len(facts) will return 4, but the arrays last index is 3.
fact_to_display = random.randint(0, len(facts)-1)

# Display the fact at the position of fact_to_display
print(facts[fact_to_display])

Extension

Extend the program to include three more facts. Then implement input validation, which asks the user if they want another fun fact. If the user says yes, another fact should be picked at random and displayed to the user. This should be repeatable until the user says no.

Welsh is one of the oldest living languages in Europe.

Want another fact? Yes
Bananas are berries, but strawberries aren't.

Want another fact? Yes
Octopuses have three hearts.

Want another fact? No

Target

You should be able to use 1-D Arrays to solve a problem.