w w w . w d . c h a t
🗣 Wd提问
ai作诗小程序
🤖 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]
}

List of possible verbs
verbs = {
nature: [sways, grows, flows, shines, blooms],
love: [beats, kisses, hugs, dates, romances],
stars: [twinkles, shines, glitters, sparkles, glows],
moon: [glows, shines, phases, eclipses, orbits],
sunset: [sets, dips, sinks, glows, fades]
}

List of possible adjectives
adjectives = {
nature: [beautiful, serene, calm, peaceful, tranquil],
love: [tender, loving, romantic, warm, fuzzy],
stars: [sparkling, twinkling, glittering, shining, glowing],
moon: [lunar, silvery, glowing, full, bright],
sunset: [orange, pink, red, golden, vibrant]
}

def generate_poem(theme):
poem = []
noun = random.choice(nouns[theme])
verb = random.choice(verbs[theme])
adjective = random.choice(adjectives[theme])

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.
0
📍
IP地址 34.16.237.120
🔍
搜索次数 216
提问时间 2025-09-30 17:44:06

📣 商家广告

公司

公司

取名

取名

广东过滤器

广东过滤器

🛒 域名购买

热门提问

🌐 域名评估

最新挖掘

🖌 热门作画

🤝 关于我们

🗨 加入群聊
💬选择任意群聊,与同好交流分享

🔗 友情链接

🧰

站长工具

📢

温馨提示

本站所有 ❓️ 问答 由Ai自动创作,内容仅供参考,若有误差请用"联系"里面信息通知我们人工修改或删除。

👉

技术支持

本站由 🟢 豌豆Ai 提供技术支持,使用的最新版: 《豌豆Ai站群搜索引擎系统 V.25.10.25》 搭建本站。

上一篇 51426 51427 51428 下一篇