Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | None | 0 0
  1. """ Settlement Generator """
  2. #Imports the random module
  3. import random
  4.  
  5. #Creates a new class called Settlement
  6. class Settlement():
  7.     #Sets the population size to a number from 0-20
  8.     populationSize = random.choice(range(20))
  9.     #Makes a blank list that we can fill with people later
  10.     denizenList = []
  11.    
  12.     #__init__ is called when an object of the class is created
  13.     def __init__(self):
  14.         #runs the populateSettlement function
  15.         self.populateSettlement()
  16.    
  17.     #This function generates people
  18.     def generatePerson(self):
  19.         #This sub-function generated names for the people
  20.         def generatePersonName():
  21.             #List of syllables to pick from
  22.             nameSyllables = [
  23.             "ka", "ke", "ki", "ko", "ku",
  24.             "ba", "be", "bi", "bo", "bu",
  25.             "ta", "te", "ti", "to", "tu",
  26.             "ga", "ge", "gi", "go", "gu",
  27.             "ja", "je", "ji", "jo", "ju"
  28.             "sa", "se", "si", "so", "su"]
  29.            
  30.             #Choosing the number of syllables for each name
  31.             firstNameSyllables  = random.choice(range(1,4))
  32.             lastNameSyllables   = random.choice(range(1,3))
  33.            
  34.             #Creates the blank names, we will fill these later
  35.             firstName   = ""
  36.             lastName    = ""
  37.             fullName    = ""
  38.            
  39.             #For each number in the sequence 1-whatever number was generated
  40.             for x in range(firstNameSyllables):
  41.                 #add a random syllable to our blank firstName variable
  42.                 firstName += random.choice(nameSyllables)
  43.            
  44.             #See above, but this time for last name
  45.             for x in range(lastNameSyllables):
  46.                 lastName += random.choice(nameSyllables)
  47.                
  48.             #Concatanate first and last names to make a full name
  49.             fullName = firstName.capitalize() + " " + lastName.capitalize()
  50.             #Output that full name
  51.             return fullName
  52.        
  53.         def generatePersonJob():
  54.             jobList = [
  55.             "General Merchant",
  56.             "Blacksmith",
  57.             "Tailor",
  58.             "Cobbler",
  59.             "Tanner",
  60.             "Doctor",
  61.             "Wicken",
  62.             "Wizard",
  63.             "Healer",
  64.             "Chef",
  65.             "Baker",
  66.             "Mercenary",
  67.             "Arms Merchant",
  68.             "Undertaker",
  69.             "Executioner",
  70.             "Carpenter",
  71.             "Conjourer",
  72.             "Stable Worker",
  73.             "Falconer",
  74.             "Hunter",
  75.             "Farmer",
  76.             "Banker",
  77.             "Soldier",
  78.             "Librarian"
  79.             ]
  80.            
  81.             job = random.choice(jobList)
  82.             return job
  83.            
  84.        
  85.         #set name equal to the full name we just generated in the above function   
  86.         name = generatePersonName()
  87.         #Pick a random number for age
  88.         age = random.choice(range(1,90))
  89.         #Pick a random job
  90.         job = generatePersonJob()
  91.        
  92.         #Create a data dict that holds the name and age
  93.         person = {"Name":name, "Age":age, "Job":job}
  94.         #output the data dict we just made
  95.         return person
  96.        
  97.     def populateSettlement(self):
  98.         #For every number 1-the size of the population
  99.         for x in range(self.populationSize):
  100.             #create a new person and add them to the denizen list
  101.             self.denizenList.append(self.generatePerson())
  102.    
  103.     #Can be called from outwith the class to get the size
  104.     def getSize(self):
  105.         return self.populationSize
  106.        
  107.     #Can be called from outwith the class to get the denizen list
  108.     def getDenizens(self):
  109.         return self.denizenList
  110.  
  111. #Make a new settlement called ukuhara
  112. #Doing this runs the __init__() in the Settlement class
  113. ukuhara = Settlement()
  114.  
  115. print("Age" + " " + "Name")
  116. print("--------------------------------")
  117.  
  118. #For every item in the denizen list of Ukuhara
  119. for x in ukuhara.getDenizens():
  120.     #Print that persons age and name
  121.     print(str(x["Age"])+ "          " + x["Name"]+ "            " + x["Job"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement