I'm trying to make my 'hacking' portion of a Fallout terminal simulator more akin to what is actually in the game. I'm in the process of setting it up so that it uses a word list, picks some words from it, and then puts them into the list of address-like display. However, because the length of the words ranges from 4 letters (FISH) to 12 letters (Hippopotamus), the lines get staggered, and the pipes I'm using to separate the options no longer line up.
I tried using an answer I found here, which works fine for ust spaces but trying to insert
{"+varNameHere+":<15}".format(a)
in the middle of the string,
(typing_.typingPrint('0xCC01 |{)&@*'+"{:"+fillerChar+"^12}".format(words[0])+'@ |0xCC02 |!(#'+"{:"+fillerChar+"^12}".format(words[0])+'@)!#\n')
, throws an ValueError about there only being one '}' in the format string. I understand what the error is talking about, but the reason for my question is, Is there anyway to have the padding character be randomly decided when the string is printed out into the terminal window?
Code:
possibleChars = ['!','@','#','$','%','^','&','*','(',')',';',':']
fillerChar = random.sample(possibleChars)
print('0xCC01 |{)&@*'+"{:"+fillerChar+"^12}".format(words[0])+'@ |0xCC02 |!(#'+"{:"+fillerChar+"^12}".format(words[0])+'@)!#\n')
Create a random 15-character string. Then extract a slice of it long enough to pad out what you want.
random_string = 'weopi94nf0683d0'
word = 'FISH'
left = (len(random_string) - len(word)) // 2
right = left + len(word)
padded_word = random_string[:left] + word + random_string[right:]