Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 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.         #set name equal to the full name we just generated in the above function   
  54.         name = generatePersonName()
  55.         #Pick a random number for age
  56.         age = random.choice(range(1,90))
  57.        
  58.         #Create a data dict that holds the name and age
  59.         person = {"Name":name, "Age":age}
  60.         #output the data dict we just made
  61.         return person
  62.        
  63.     def populateSettlement(self):
  64.         #For every number 1-the size of the population
  65.         for x in range(self.populationSize):
  66.             #create a new person and add them to the denizen list
  67.             self.denizenList.append(self.generatePerson())
  68.    
  69.     #Can be called from outwith the class to get the size
  70.     def getSize(self):
  71.         return self.populationSize
  72.        
  73.     #Can be called from outwith the class to get the denizen list
  74.     def getDenizens(self):
  75.         return self.denizenList
  76.  
  77. #Make a new settlement called ukuhara
  78. #Doing this runs the __init__() in the Settlement class
  79. ukuhara = Settlement()
  80.  
  81. print("Age" + "         " + "Name")
  82. print("--------------------------------")
  83.  
  84. #For every item in the denizen list of Ukuhara
  85. for x in ukuhara.getDenizens():
  86.     #Print that persons age and name
  87.     print(str(x["Age"])+ "          " + x["Name"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement