#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    No idea how to do this


    I've made a program which generates a madlib for the gettysburg address (school project), and now I have
    to make it so that verbs and nouns which are identical in the original gettysburg address are identical in the madlib.

    "Four score and seven NOUNs ago our NOUNs VERBed forth on this NOUN a ADJECTIVE NOUN1, VERBed in NOUN, and VERBed to the NOUN that all NOUN2s are VERBed equal.



    Now we are VERBed in a ADJECTIVE civil NOUN, VERBing whether that NOUN1, or any NOUN1 so VERBed and so VERB1ed, can long NOUN. We are met on a great NOUN3 of that NOUN. We have come to VERB1 a portion of that NOUN3, as a ADJECTIVE resting NOUN for those who here gave their lives that that NOUN1 might live. It is altogether fitting and proper that we should do this.

    Code:
    "Four score and seven NOUNs ago our NOUNs VERBed forth on this NOUN a ADJECTIVE NOUN1, VERBed in NOUN, and VERBed to the NOUN that all NOUN2s are VERBed equal.
    
    
    
    Now we are VERBed in a ADJECTIVE civil NOUN, VERBing whether that NOUN1, or any NOUN1 so VERBed and so VERB1ed, can long NOUN. We are met on a great NOUN3 of that NOUN. We have come to VERB1 a portion of that NOUN3, as a ADJECTIVE resting NOUN for those who here gave their lives that that NOUN1 might live. It is altogether fitting and proper that we should do this.
    
    
    
    But, in a larger sense, we can not VERB1, we can not VERB2, we can not VERB this NOUN. The ADJECTIVE NOUN2, living and dead, who VERBed here, have VERB2ed it, far above our ADJECTIVE NOUN to VERB or VERB. The NOUN will little note, nor long VERB what we VERB here, but it can never VERB what they did here. It is for us the living, rather, to be VERBed here to the ADJECTIVE NOUN which they who VERB here have thus far so nobly VERBed. It is rather for us the living, rather, to be here VERB1ed to the ADJECTIVE NOUN remaining before us that from these ADJECTIVE NOUN we take increased devotion to that cause for which they gave the last full measure of devotion that we here highly resolve that these dead shall not have VERBed in vain that this NOUN1, under God, shall have a new birth of NOUN and that NOUN of the NOUN9, by the NOUN9, for the NOUN9, shall not VERB from the NOUN.
    The program replaces VERB and NOUN with a random verb/noun, but now I need to make verb1, verb2, noun1, noun2, etc. Be consistent throughout the madlib. I used to be an avid python user, but I've forgot a lot of it. I have no idea how I would do this. I think there are these things called tags, but there were no results for it on google. Also, I could name a unique variable based on what I'm replacing, so if x in integers: verb+"x" = randomVerb. I used to know how to do this but I forgot.

    Here's my code:
    Code:
    storyy="""Four score and seven NOUNs ago our NOUNs VERBed forth on this NOUN a ADJECTIVE NOUN1, VERBed in NOUN, and VERBed to the NOUN that all NOUN2s are VERBed equal.
    
    
    
    Now we are VERBed in a ADJECTIVE civil NOUN, VERBing whether that NOUN1, or any NOUN1 so VERBed and so VERB1ed, can long NOUN. We are met on a great NOUN3 of that NOUN. We have come to VERB1 a portion of that NOUN3, as a ADJECTIVE resting NOUN for those who here gave their lives that that NOUN1 might live. It is altogether fitting and proper that we should do this.
    
    
    
    But, in a larger sense, we can not VERB1, we can not VERB2, we can not VERB this NOUN. The ADJECTIVE NOUN2, living and dead, who VERBed here, have VERB2ed it, far above our ADJECTIVE NOUN to VERB or VERB. The NOUN will little note, nor long VERB what we VERB here, but it can never VERB what they did here. It is for us the living, rather, to be VERBed here to the ADJECTIVE NOUN which they who VERB here have thus far so nobly VERBed. It is rather for us the living, rather, to be here VERB1ed to the ADJECTIVE NOUN remaining before us that from these ADJECTIVE NOUN we take increased devotion to that cause for which they gave the last full measure of devotion that we here highly resolve that these dead shall not have VERBed in vain that this NOUN1, under God, shall have a new birth of NOUN and that NOUN of the NOUN9, by the NOUN9, for the NOUN9, shall not VERB from the NOUN.
    
    """
    import random
    story=list(storyy)
    noun=["fish","sheep","goat","toilet","bathroom","chicken","hamster","underwear","apple","banana","cabbage","feather","donkey","spoon","egg","dinosaur","soccer ball","airplane","bird","breakfast","crayon"]
    verb=["run","walk","jump","fart","eat","drink","smash","faceplant","fail","burp","bark","climb","crash","debate","dig","dive","flick","float","greet","hide","lick","parachute","pilot","roll","smell",]
    adjective=["big","small","better","smelly","stinky","green","ancient","tricky","crazy","striped","empty","slippery","wet","massive","miniature","odd","silly","weird","icy","purple","quick"]
    integers=[1,2,3,4,5,6,7,8,9]
    def madlib():
    
    	story=storyy.split("NOUN")
    	new=[]
    	for i in range(0,len(story)):
    		if story[i+1][0] in integers: 
    			getName(story[i+1][i])
    			new.append(i+" "+noun[random.randint(0,len(noun)-1)])
    	rr= "".join(new)	
    	storyyy=rr.split("VERB")
    	xx=[]
    	for i in storyyy:
    		xx.append(i+" "+verb[random.randint(0,len(verb)-1)])
    
    	xman= "".join(xx)
    	
    	xstory=xman.split("ADJECTIVE")
    	n=[]
    	for i in xstory:
    		n.append(i+" "+adjective[random.randint(0,len(adjective)-1)])
    	return "".join(n)
    Thanks.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Make an empty dictionary.
    Start translating your code.
    When you find (for example) NOUN1 look in your dictionary for the key 'NOUN1'. If it is not in the dictionary choose a random noun, put it in the dictionary. Next substitute the value associated with the key 'NOUN1'.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0
    Thanks, I think that'll work.

    But I'm getting an error right now with this:

    Code:
    	for i in range(0,len(story)):
    		if story[i+1][0] in integers: 
    			if "NOUN"+str(story[i+1][0]) in dictionary:
    				new.append(i+" "+dictionary[str(story[i+1][0])]
    			else:
    				dictionary[str(story[i+1][0])]="NOUN"+str(story[i+1][0])
    
    		else:
    			new.append(i+" "+noun[random.randint(0,len(noun)-1]
    else:
    ^
    SyntaxError: invalid syntax

    It looks like I've got my closing brackets and paranthesis to me.

    Edit: got it fixed, still having more syntax errors but I can fix them easily.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    new.append(i+" "+dictionary[str(story[i+1][0])])
    Last edited by b49P23TIvg; April 5th, 2014 at 08:21 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0
    I'm almost done, but I've been getting a tab error, been trying to figure it out all morning.

    Code:
    def madlib():
    	integers=[1,2,3,4,5,6,7,8,9]
    	dictionary={}
    	story=storyy.split("NOUN")
    	new=[]
    	
    	print story	
    	for i in range(0,len(story)):
    		if i+1<len(story):
    			print inte(story[i+1][0])
    			print integers
    			print inte(story[i+1][0]) in integers
    			if inte(story[i+1][0]) in integers: 
    				print dictionary
    				if str(story[i+1][0]) in dictionary:
    					print str(story[i+1][0])
    					print "XXXXXXX"
    					new.append(story[i]+" "+dictionary[str(story[i+1][0])])
    				else:
    					print "AAAAAAAA"
    					dictionary[str(story[i+1][0])]=noun[random.randint(0,len(noun)-1)]
    					
    			else:
    				new.append(story[i]+" "+noun[random.randint(0,len(noun)-1)])
    		if i+1>len(story):
    			new.append(story[i]+" "+noun[random.randint(0,len(noun)-1)])
    			
    		
    	rr="".join(new)
    	dictionaryVerb={}
    	Thestory=rr.split("VERB")
    	xx=[]
    	
    		
    	for i in range(0,len(Thestory)):
    	
    		if i+1<len(Thestory):
    		
    			if inte(Thestory[i+1][0]) in integers: 
    				print dictionaryVerb		
    				if str(Thestory[i+1][0]) in dictionaryVerb:
    					print str(Thestory[i+1][0])
    					print "ABABABABAB"	
    					print Thestory[i]+" "+dictionaryVerb[str(Thestory[i+1][0])]
    					print dictionaryVerb
    					xx.append(Thestory[i]+" "+dictionaryVerb[str(Thestory[i+1][0])])
    					print xx
    				else:
    						
    					dictionaryVerb[str(Thestory[i+1][0])]=verb[random.randint(0,len(verb)-1)]
    				
    			else:
    				xx.append(Thestory[i]+" "+verb[random.randint(0,len(verb)-1)])
    		if i+1>len(Thestory):
    			xx.append(Thestory[i]+" "+verb[random.randint(0,len(verb)-1)])
    			
    
    		
    
    	xman= "".join(xx)
    	
    	xstory=xman.split("ADJECTIVE")
    	n=[]
    	for i in xstory:
    		n.append(i+" "+adjective[random.randint(0,len(adjective)-1)])
            return n
    Incosistent identation on the last line. "return n"

    Edit: reset my code and that seemed to work.

IMN logo majestic logo threadwatch logo seochat tools logo