我应该查看Python文档的哪个区域才能完成以下任务:
npc_gender = ["Male","Female"]
npc_age = # trying to do random integer within a range say 18-80
npc_name_male = ["Arnold","Bob","Charles","David","Edward"]
npc_name_female = ["Annie","Barbara","Courtney","Danielle","Ellen"]
""" Obviously, the names are gender specific for an if/else statement :) """
npc_weight = # trying to figure out how to do range...not sure yet, but still variable.
npc_height = # same a weight...not sure yet.
def create_npc():
if npc_gender == "Male"
# select (automatically) one of the npc_name_male[#:] and store.
return npc_name_male[#:]
elif npc_gender == "Female"
# select (automatically) one of the npc_name_female[#:] and store.
else:
return现在我是confused...basically,我想让程序从已经存储在变量中的一组参数中创建一个字符...
我的方向对吗?提前谢谢。
对Blender的响应:
import random
npc_gender = ["Male","Female"]
def create_npc():
npc_gender_choice = random.choice(npc_gender)
print(npc_gender_choice)
create_npc()我这样做了,它帮助我理解。我将继续工作,直到我所有的工作,然后将更新帖子。谢谢!
发布于 2013-04-19 07:07:55
您可以使用random.choice()来获取随机元素:
import random
...
choice = random.choice(npc_name_male)https://stackoverflow.com/questions/16094556
复制相似问题