Random Sentence Generator

  • Share this:

Code introduction


The function generates a random sentence. The words in the sentence come from a predefined list of words. The length of the sentence is randomly determined.


Technology Stack : random, datetime, math

Code Type : Python Function

Code Difficulty : Intermediate


                
                    
import random
import datetime
import math

def generate_random_sentence():
    words = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew", "kiwi", "lemon"]
    sentence_length = random.randint(3, 10)
    sentence = ' '.join(random.sample(words, sentence_length))
    return sentence