-1

I'm extremely new to programming so I apologize if this is a rookie mistake.

#import statements

#function definitions
useradj1=input(str("Please enter an adjective. ")) #asks for adjective
usernoun1=input(str("Please enter a noun. ")) #asks for noun
userverbpasttense1=input(str("Please enter a verb in the past tense. ")) #asks for verb in past tense
useradverb1=input(str("Please enter an adverb. ")) #asks for adverb
useradj2=input(str("Please enter an adjective. ")) #asks for adjective
usernoun2=input(str("Please enter a noun. ")) #asks for noun
usernoun3=input(str("Please enter a noun. ")) #asks for noun
useradj3=input(str("Please enter an adjective. ")) #asks for adjective
userverb1=input(str("Please enter a verb. ")) #asks for verb
useradverb2=input(str("Please enter an adverb. ")) #asks for adverb
userverbpasttense2=input(str("Please enter a verb in the past tense. ")) #asks for verb in past tense
useradj4=input(str("Please enter an adjective. ")) #asks for adjective




madlibs=dict() #creates dictionary for madlibs
madlibs["adj1"]= useradj1 
madlibs["noun1"]=usernoun1
madlibs["verbpasttense1"]=userverbpasttense1
madlibs["adverb1"]=useradverb1
madlibs["adj2"]=useradj2
madlibs["noun2"]=usernoun2
madlibs["noun3"]=usernoun3
madlibs["adj3"]=useradj3
madlibs["verb1"]=userverb1
madlibs["adverb2"]=useradverb2
madlibs["verbpasttense2"]=userverbpasttense2
madlibs["adj4"]=useradj4

#programming logic
#below is main print statement
print("Today I went to the zoo. I saw a(n) "+str(madlibs["adj1"])+str(madlibs["noun1"])" jumping up and down in its tree. "+str(madlibs["verbpasttense1"])+str(madlibs["adverb1"]) "through the large tunnel that led to its "+str(madlibs["adj2"])+str(madlibs["noun2"])  "I got some peanuts and passed them through the cage to a gigantic gray "+str(madlibs["noun3"])" towering above my head. Feeding that animal made me hungry. I went to get a "+str(madlibs["adj3"]) "scoop of ice cream. It filled my stomach. Afterwards I had to "+str(madlibs["verb1"])+str(madlibs["adverb2"]) "to catch our bus. When I got home I "+str(madlibs["verbpasttense2"]) "my mom for a "+str(madlibs["adj4"]) "day at the zoo.")

Whenever I try it out I get a syntax error around where i'm printing "verb1". What can I do to fix this? Also, this isnt as important but I have no clue how to seperate my text instead of just having it on one line. If you can help with that as well that would be wonderful.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

0

Long lines of code like this are often very hard to debug. You missed out on a few + signs on that line. Here is a fixed line of code:

print("Today I went to the zoo. I saw a(n) "+str(madlibs["adj1"])+str(madlibs["noun1"])+" jumping up and down in its tree. "+str(madlibs["verbpasttense1"])+str(madlibs["adverb1"]) +"through the large tunnel that led to its "+str(madlibs["adj2"])+str(madlibs["noun2"])  + "I got some peanuts and passed them through the cage to a gigantic gray "+str(madlibs["noun3"]) + " towering above my head. Feeding that animal made me hungry. I went to get a "+str(madlibs["adj3"]) + "scoop of ice cream. It filled my stomach. Afterwards I had to "+str(madlibs["verb1"])+str(madlibs["adverb2"]) + "to catch our bus. When I got home I "+str(madlibs["verbpasttense2"]) + "my mom for a "+str(madlibs["adj4"]) + "day at the zoo.")

You could also make use of f-strings from Python 3.6:

print(f"Today I went to the zoo. I saw a(n) { str(madlibs['adj1']) } { str(madlibs['noun1']) } jumping up and down in its tree. {str(madlibs['verbpasttense1'])} {str(madlibs['adverb1'])} through the large tunnel that led to its {str(madlibs['adj2'])} {str(madlibs['noun2'])}. I got some peanuts and passed them through the cage to a gigantic gray {str(madlibs['noun3'])} towering above my head. Feeding that animal made me hungry. I went to get a(n) {str(madlibs['adj3'])} scoop of ice cream. It filled my stomach. Afterwards I had to {str(madlibs['verb1'])} {str(madlibs['adverb2'])} to catch our bus. When I got home I {str(madlibs['verbpasttense2'])} my mom for a {str(madlibs['adj4'])} day at the zoo.")

I strongly suggest breaking it up into multiple lines, one for each sentence, maybe.

Robinson
  • 300
  • 3
  • 12