V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Zoeeeeecho
V2EX  ›  Python

Python 随机生成句子

  •  
  •   Zoeeeeecho · 2022-09-21 16:27:43 +08:00 · 1450 次点击
    这是一个创建于 555 天前的主题,其中的信息可能已经有所发展或是发生改变。
    苯人刚学 python ,作业要求以主谓宾三个部分 define 三个从列表里随机选一个元素的函数,最后组成主谓宾形式的句子并重复输出 10 次。我只会用 choice ()来随机从列表里选元素,想知道怎么 def 一个随机选元素的函数。苯人刚学,问的问题大多很蠢,大家见谅!谢谢大家帮助!
    3 条回复    2022-09-22 09:53:10 +08:00
    Via8veritas
        1
    Via8veritas  
       2022-09-21 16:52:49 +08:00
    target_list[radom(0, len(target_list))]
    我理解是这样?
    还是说你想自己实现随机数的函数?
    fgwmlhdkkkw
        2
    fgwmlhdkkkw  
       2022-09-21 18:28:33 +08:00
    额,每个循环 choice3 次,循环 10 次。
    ruanimal
        3
    ruanimal  
       2022-09-22 09:53:10 +08:00
    感觉不是笨是懒
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2856 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:40 · PVG 19:40 · LAX 04:40 · JFK 07:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.