python - Print only the characters below a specific word in a line -


i'm trying write script 2 different things: picks random word , causes "jump" out of line, , "turns" on word. turn, mean picks random word , prints same number of characters word beneath it, , nothing else, so:

this thing typing           sdfas           wertq           wsvsd           swefs 

this mean making "jump" out of line:

          thing       typing 

my problem cannot figure out how "print [x] number of characters under x"

here code, below:

import random import sys  s = open('sonnets.txt')  counting = 0  line in s:     line.strip()     randomint = random.randint(1,100)     counting = counting+1     words = line.split()     test = 1     if (randomint < 2*counting):         if (len(words) > 0):             r = random.choice(words)             if r in line:                 ind = line.index(r)                 wordchoice = len(r)                 print ((" " * (ind))+r).upper()                 whitespace = wordchoice+2                 newline = line.replace(r, (" " * whitespace))                 print newline             turn = random.choice(words)             if turn in line:                 turncheck = true                  ind = line.index(turn)                 wordchoice = len(turn)                 print ((" " * (ind))+turn)                 foo = line[ind:ind+4]                 print ((" " * (ind))+foo)        else:         print line  

the above code runs, succeeds in making text "jump". can creating column of words?

again, give appreciated. thank you!

txt='this thing typing'  jumpword='thing' jumpind=txt.find(jumpword) newtxt=str(txt) if jumpind>=0:     newtxt=newtxt.replace(jumpword," "*len(jumpword),1)     newtxt=" "*jumpind+jumpword+'\n'+newtxt  print newtxt 

result:

          thing       typing 

the word turning:

import random def randword(length,sourcelist):     # random word: (move out of function if need keep same)     rword=random.sample(sourcelist,1)[0]     # length number of letters it.     return "".join(map(lambda dummy:random.sample(rword,1)[0],range(length)))  print txt # make 5 turns: in range(5):     print " "*jumpind+randword(len(jumpword),txt.split()) 

result:

this thing typing           iiiii           aaaaa           iiiii           yngtt           hthti 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -