First Timer - Madlibs Project


#1

HI,

first time coder and really struggling to complete this project. I dont know where my error is in the code.

  • I've scoured for comma errors

  • My %s = the variables to the right of the %

  • I feel I have followed all of the step by steps in the task list and even used the hints.

this is the error I am receiving in the terminal:

$ python Madlibs.py
File "Madlibs.py", line 34
print STORY % (adj1, name, verb1, adj2, noun1, nou
n2, animal, food, verb2, noun3, fruit, adj3, name, ver
b3, number, name, superhero, superhero, name, country,
name, dessert, name year, noun4)

                    ^

SyntaxError: invalid syntax

"""This is a game of Madlibs I designed and coded myself!

Author: Brandon Clark
"""

print "Mad Libs has started!"

name = raw_input("Enter a name: ")

adj1 = raw_input("Enter an adjective: ")
adj2 = raw_input("Enter one more adjective: ")
adj3 = raw_input("Enter the last adjective: ")

verb1 = raw_input("Enter a verb: ")
verb2 = raw_input("Enter one more verb: ")
verb3 = raw_input("Enter the last verb: ")

noun1 = raw_input("Enter a noun: ")
noun2 = raw_input("Enter a second noun: ")
noun3 = raw_input("Enter one more noun: ")
noun4 = raw_input("Enter the last noun: ")

animal = raw_input("Enter an animal: ")
food = raw_input("Enter a food: ")
fruit = raw_input("Enter a fruit: ") 
number = raw_input("Enter a number: ")
superhero = raw_input("Enter a superhero name: ")
country = raw_input("Enter a country: ")
dessert = raw_input("Enter a dessert: ")
year = raw_input("Enter a year: ")

#The template for the story
STORY = "This morning I woke up and felt %s because %s was going to finally %s over the big %s %s. On the other side of the %s were many %s protesting to keep %s in stores. The crowd began to %s to the rythym of the %s, which made all of the %s very %s. %s tried to %s into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping %s into a puddle of %s. %s then fell asleep and woke up in the year %s, in a world where %s ruled the world." 

print STORY % (adj1, name, verb1, adj2, noun1, noun2, animal, food, verb2, noun3, fruit, adj3, name, verb3, number, name, superhero, superhero, name, country, name, dessert, name year, noun4)


#2

The only error that jumps out at me is the count mismatch.

# count `%s` == 25

# count `, `  == 23

This tells me there are only 24 items in the tuple, the last formatter has no value.


#3

Found it! I did have one too many %s, and I was missing a comma between (name story) in the print STORY section at the bottom.

Thanks for helping me break through the wall!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.