Foxscotch

ottoman.py

Jan 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. import random
  2.  
  3.  
  4. def int_to_roman(input):
  5.     """
  6.    Code from http://code.activestate.com/recipes/81611-roman-numerals/
  7.    Changes made to raise statements for Python 3 compatibility
  8.    """
  9.     if type(input) != type(1):
  10.         raise TypeError("expected integer, got %s" % type(input))
  11.     if not 0 < input < 4000:
  12.         raise ValueError("Argument must be between 1 and 3999")
  13.     ints = (1000, 900,  500, 400, 100,  90, 50,  40, 10,  9,   5,  4,   1)
  14.     nums = ('M',  'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I')
  15.     result = ""
  16.     for i in range(len(ints)):
  17.         count = int(input / ints[i])
  18.         result += nums[i] * count
  19.         input -= ints[i] * count
  20.     return result
  21.  
  22.    
  23. names = ['Suleiman',
  24.          'Osman',
  25.          'Bayezid',
  26.          'Mehmed',
  27.          'Orhan',
  28.          'Murad',
  29.          'Selim']
  30.  
  31. suffixes = [' the Magnificent',
  32.             ' the Lawgiver',
  33.             ' the Conqueror',
  34.             ' the Terrible',
  35.             ' the Stammerer',
  36.             ' the Fair',
  37.             ' the Great',
  38.             ' the Silent']
  39.  
  40. full_names = []
  41.  
  42. for i in range(10):
  43.     full_names.append('Sultan ' + random.choice(names))
  44.  
  45. for j in reversed(range(len(full_names))):
  46.     occurences = full_names.count(full_names[j])
  47.     if occurences > 1:
  48.         full_names[j] += ' ' + int_to_roman(occurences)
  49.  
  50. already_used = []
  51. already_used2 = []
  52. for k in range(3):
  53.     # full_name = random.choice(full_names) + random.choice(suffixes)
  54.     # full_names[random.randint(0, len(full_names) - 1)] = full_name
  55.    
  56.     num = random.randint(0, len(full_names) - 1)
  57.     while num in already_used:
  58.         num = random.randint(0, len(full_names) - 1)
  59.     already_used.append(num)
  60.    
  61.     num2 = random.randint(0, len(suffixes) - 1)
  62.     while num2 in already_used2:
  63.         num2 = random.randint(0, len(suffixes) - 1)
  64.     already_used2.append(num2)
  65.    
  66.     full_names[num] += suffixes[num2]
  67.    
  68.  
  69. print('\n'.join(full_names))
Add Comment
Please, Sign In to add comment