Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Settlement Generator """
- #Imports the random module
- import random
- #Creates a new class called Settlement
- class Settlement():
- #Sets the population size to a number from 0-20
- populationSize = random.choice(range(20))
- #Makes a blank list that we can fill with people later
- denizenList = []
- #__init__ is called when an object of the class is created
- def __init__(self):
- #runs the populateSettlement function
- self.populateSettlement()
- #This function generates people
- def generatePerson(self):
- #This sub-function generated names for the people
- def generatePersonName():
- #List of syllables to pick from
- nameSyllables = [
- "ka", "ke", "ki", "ko", "ku",
- "ba", "be", "bi", "bo", "bu",
- "ta", "te", "ti", "to", "tu",
- "ga", "ge", "gi", "go", "gu",
- "ja", "je", "ji", "jo", "ju"
- "sa", "se", "si", "so", "su"]
- #Choosing the number of syllables for each name
- firstNameSyllables = random.choice(range(1,4))
- lastNameSyllables = random.choice(range(1,3))
- #Creates the blank names, we will fill these later
- firstName = ""
- lastName = ""
- fullName = ""
- #For each number in the sequence 1-whatever number was generated
- for x in range(firstNameSyllables):
- #add a random syllable to our blank firstName variable
- firstName += random.choice(nameSyllables)
- #See above, but this time for last name
- for x in range(lastNameSyllables):
- lastName += random.choice(nameSyllables)
- #Concatanate first and last names to make a full name
- fullName = firstName.capitalize() + " " + lastName.capitalize()
- #Output that full name
- return fullName
- #set name equal to the full name we just generated in the above function
- name = generatePersonName()
- #Pick a random number for age
- age = random.choice(range(1,90))
- #Create a data dict that holds the name and age
- person = {"Name":name, "Age":age}
- #output the data dict we just made
- return person
- def populateSettlement(self):
- #For every number 1-the size of the population
- for x in range(self.populationSize):
- #create a new person and add them to the denizen list
- self.denizenList.append(self.generatePerson())
- #Can be called from outwith the class to get the size
- def getSize(self):
- return self.populationSize
- #Can be called from outwith the class to get the denizen list
- def getDenizens(self):
- return self.denizenList
- #Make a new settlement called ukuhara
- #Doing this runs the __init__() in the Settlement class
- ukuhara = Settlement()
- print("Age" + " " + "Name")
- print("--------------------------------")
- #For every item in the denizen list of Ukuhara
- for x in ukuhara.getDenizens():
- #Print that persons age and name
- print(str(x["Age"])+ " " + x["Name"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement