🤖 Ai回答: Here's a simple poem generator using Python and the `random` library、This program will generate a short poem with a random theme, rhyming scheme, and structure.
python
import random
List of possible themes
themes = [nature, love, stars, moon, sunset]
List of possible nouns
nouns = {
nature: [mountain, river, tree, flower, lake],
love: [heart, kiss, hug, date, romance],
stars: [star, galaxy, space, planet, universe],
moon: [moonlight, lunar, eclipse, phase, orbit],
sunset: [sun, sky, orange, pink, dusk]
}
First line
poem.append(fIn the {adjective} {theme}, the {noun} {verb}.)
Second line
poem.append(fIt {verb}s with a gentle, loving light.)
Third line
poem.append(fThe {noun} is so {adjective} and bright.)
Fourth line
poem.append(fIt fills my heart with delight.)
return \n.join(poem)
def main():
print(Welcome to the poem generator!)
theme = random.choice(themes)
print(fToday's theme is: {theme})
print(generate_poem(theme))
if __name__ == __main__:
main()
Example Output:
Welcome to the poem generator!
Today's theme is: sunset
In the vibrant sunset, the sun sets.
It sets with a gentle, loving light.
The sun is so orange and bright.
It fills my heart with delight.
How it works:
1、The program first defines lists of possible themes, nouns, verbs, and adjectives.
2、The `generate_poem` function takes a theme as input and selects a random noun, verb, and adjective from the corresponding lists.
3、It then constructs a short poem using these words.
4、The `main` function selects a random theme and prints out the generated poem.
Adding more features:
* You can add more themes, nouns, verbs, and adjectives to the lists to increase the variety of poems generated.
* You can modify the structure and rhyming scheme of the poem by changing the way the lines are constructed.
* You can also add user input to select the theme or other parameters of the poem.