Random Sentence Generator

  • Share this:

Code introduction


The function accepts two arguments, the first one is a list of words, and the second one specifies the number of words in the generated sentence. The function randomly selects words from the first argument to form a sentence with the specified number of words.


Technology Stack : Behave, random

Code Type : Behave custom function

Code Difficulty : Intermediate


                
                    
from behave import given, when, then
from random import choice

def generate_random_sentence(arg1, arg2):
    words = arg1.split()
    sentence = ' '.join(choice(words) for _ in range(arg2))
    return sentence                
              
Tags: