String Formatting with %, Part 2


#1

How would I define a raw_input??? This is the example we had to complete and I it with no trouble

name = raw_input(“What is your name?”)
quest = raw_input(“What is your quest?”)
color = raw_input(“What is your favorite color?”)

print "Ah, so your name is ___, your quest is ___, "
“and your favorite color is ___.” ___ (name, quest, color)

But when I created my own it gave me an error even though I kinda just copied it. MY Work v

name = ram_input(“What is your name?”)
age = ram_input(“What is your age?”)
live = ram_input(“Where do you live”)

print “Wow that’s so cool, My name is also %s, I’, also %s, and I live in the same area as you %s.” % (name,age,live)

The error is: Traceback (most recent call last):
File “python”, line 7, in
NameError: name ‘ram_input’ is not defined

HELP!?


#2

You shouldn’t define it at all, it exists when you start python. It refers to a function, and that function does something, and if that something is something you wish to leverage, then you might want to call that function

If you get an error message saying something isn’t defined, that doesn’t mean that you should define it. Python does not know what you want, it can never tell you what you should do. You always have to make your own decisions.

What error messages can tell you though, is why something could not be executed, so read the error message carefully, compare to the code it mentions, and compare to what you meant.


#3

Hi you should write: raw_input instead of ram_input. Just delete M and write W


#4

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