每当我在 Python 中使用 random.choice 时,我都会收到错误消息。错误在 'body' 页面

Whenever i use random.choice in Python, i get an error. The error is in the 'body' page

playsound.playsound(random.choice(beatboxes))

AttributeError: 'builtin_function_or_method' 对象没有属性 'choice'

进程已完成,退出代码为 1

有没有 bultin 随机模块的替代品?

谢谢

要像您在代码中编写的那样使用随机选项,您需要导入

import random

这里是你的情况

from random import * 

现在可以使用了