以下是一个 Python 程序,可以循环随机从自定义词库中选择一个词,并暂停一段随机时间:

import random
import time

# 自定义词库
words = ['apple', 'banana', 'cherry', 'durian', 'elderberry']

while True:
    # 随机选择一个词
    word = random.choice(words)
    print('Selected word:', word)
    
    # 随机暂停一段时间
    pause_time = random.randint(1, 5)
    print('Pause for', pause_time, 'seconds...')
    time.sleep(pause_time)

你可以根据需要修改words列表中的词,或者添加更多的词。程序会循环运行,每次随机选择一个词并暂停一段时间。你可以根据需要修改暂停时间的范围。

Python 程序:循环随机选择词语并暂停

原文地址: https://www.cveoy.top/t/topic/nWpe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录