Run outside of Codecademy


#1

I have installed python 3. I used notepad++ to edit my script. When I try to run it in a cmd window I get an error. The error is:

File “C:\Users\Steri\OneDrive\Code\Python\MadLib.py”, line 28
print STORY % (adj1, name, verb1, adj2, noun1, noun2, animal, food, verb2, noun3, fruit, adj3, name, verb3, number, name, super_hero, super_hero, name, country, name, dessert, name, year, noun4)
^
SyntaxError: invalid syntax
<What do you expect to happen instead?>
This code worked in codecademy.

"""Python can be used for a variety of different tasks. In this project, we'll use Python to write a Mad Libs story! """

print ("Mad Libs has started.")

name = raw_input("What is your first name? ")
adj1 = raw_input("List an adjective: ")
adj2 = raw_input("List an adjective: ")
adj3 = raw_input("List an adjective: ")
verb1 = raw_input("List a verb: ")
verb2 = raw_input("List a verb: ")
verb3 = raw_input("List a verb: ")
noun1 = raw_input("List a noun: ")
noun2 = raw_input("List a noun: ")
noun3 = raw_input("List a noun: ")
noun4 = raw_input("List a noun: ")
animal = raw_input("List an animal: ")
food = raw_input("List a food: ")
fruit = raw_input("List a fruit: ")
number = raw_input("List a number: ")
super_hero = raw_input("List a super hero name: ")
country = raw_input("List a country: ")
dessert = raw_input("List a dessert: ")
year = raw_input("List 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 %ss protesting to keep %s in stores. The crowd began to %s to the rhythm 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."

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


#2

I was able to fix this error. I have to put STORY in () after print. I also had to change raw_input to just input. Now I an getting this error:

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 protesting to keep %s in stores. The crowd began to %s to the rhythm 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.
Traceback (most recent call last):
  File "C:\Users\Steri\OneDrive\Code\Python\MadLib.py", line 28, in <module>
    print (STORY) % (adj1, name, verb1, adj2, noun1, noun2, animal, food, verb2, noun3, fruit, adj3, name, verb3,  number, name, suphero, suphero, name, country, name, dessert, name, year, noun4)
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

,


#3

you use python3, so the changes you mentioned are very important, however, the print statement need to include the variables:

example = "an example"
# good
print("%s" % (example))
# not good
print("%s") % (example)

#4

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