Pythin Madlibs project


#1



I'm confused by the string formatting. I tried to run the code but it wouldn't insert the string into %s places.


SyntaxError: invalid syntax
it just prints the code out as I entered it in the editor.


STORY = Print "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 %ss protecting to keep %s in stores. The crowd began to %s to the rythym of the %s, which made all of the %ss 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 %ss ruled the world." % (first_adj, name, activity, sunny, diner, mall, Bear, omelet, wherego, store, apple, nocloud, name, how, 7, Deadpool, Deadpool, name, USA, cake, name, 2017, Computer, pad)

Replace this line with your code. 
"This program explains"
print "Hello, Madlibs has begun"
first_adj = raw_input("temper")
name = raw_input("Whatname")
activity = raw_input("what")
sunny = raw_input("bright")
diner = raw_input("dine")
mall = raw_input("mall")
Bear = raw_input("Animal")
omelet = raw_input("eggs")
wherego = raw_input("where")
store = raw_input("Micr")
apple = raw_input("fruit")
nocloud = raw_input("clear")
name = raw_input("Whatname")
how = raw_input("how")
7 = raw_input("number")
Deadpool = raw_input("supe")
Deadpool = raw_input("supe")
name = raw_input("Whatname")
USA = raw_input("country")
cake = raw_input("dessert")
name = raw_input("Whatname")
2017 = raw_input("year")
Computer = raw_input("cpu")
pad = raw_input("place")


STORY = Print "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 %ss protecting to keep %s in stores. The crowd began to %s to the rythym of the %s, which made all of the %ss 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 %ss ruled the world." % (first_adj, name, activity, sunny, diner, mall, Bear, omelet, wherego, store, apple, nocloud, name, how, 7, Deadpool, Deadpool, name, USA, cake, name, 2017, Computer, pad)

print STORY % (first_adj, "name", "activity", "sunny", "diner", "mall", "Bear", "omelet", "wherego", "store", "apple", "nocloud", "name", "how", "7", "Deadpool", "Deadpool", "name", "USA", "cake", "name", "2017", "Computer", "pad")


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


#2

So a few things here.

  1. Double-check the string that was printed for the variable STORY. A tip I would recommend is to read your code aloud. It will help you learn to notice any issues (and read it in a normal reading speed). When reading, I want to point out more specifically the modulo operators (%) here. Do you notice one of them being slightly different?

  2. Why is the STORY variable followed by a = print? Also,printshouldn't bePrint. All lowercase.

  3. Integers cannot be variables. I've noticed you have 2017 and another integer as a variable that = a raw_input. There will be a Syntax Error.

I'm not sure what the instructions are for this one, but I would take another good look at this and review what exactly it tells you to do.

I hope these helped. Let us know if you were able to solve it!


#3

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