I get an error for this code:
(there are indents just not showing on this forum)
#small program to introduce members of the family
print "Please enter the first name of a family member.", " ", "the choices are john, jane, jim, and scruffle."
text = input()
if text = "john"
print "this is john"
elif text = jane
print "this is jane"
elif text = jim
print "this is jim"
elif text = scruffle
print "RUFF!!"
I need help!!!!
Started by hds272, Oct 15 2007 01:33 PM
3 replies to this topic
#1
Posted 15 October 2007 - 01:33 PM
|
|
|
#2
Posted 15 October 2007 - 01:57 PM
First of all; the indents aren't showing, because you're not using the code-tags. Use them in your further posts.
There is four major problems in the code you posted.
1. input() is used for integers, and such, while raw_input() is used for text-input. Just think of it like: input() for numbers and raw_input() for strings.
2. Instead of using the compare-operator, ==, you're using the assignment operator, =. There's a big difference between these operators.
3. When your tries to compare in most of your if-statements, you're forgetting the double-quotes. These are necessary, or the interpreter will see them as variables - and you haven't declared those variable - which result in: error(s)
4. Languages like C++ are using curly brackets for statements, and such, while Python is using colons and indents. So, you need a ':' right after all the places where you're using a statement, e.g. if-statements.
Look at this [corrected] code:
There is four major problems in the code you posted.
1. input() is used for integers, and such, while raw_input() is used for text-input. Just think of it like: input() for numbers and raw_input() for strings.
2. Instead of using the compare-operator, ==, you're using the assignment operator, =. There's a big difference between these operators.
3. When your tries to compare in most of your if-statements, you're forgetting the double-quotes. These are necessary, or the interpreter will see them as variables - and you haven't declared those variable - which result in: error(s)
4. Languages like C++ are using curly brackets for statements, and such, while Python is using colons and indents. So, you need a ':' right after all the places where you're using a statement, e.g. if-statements.
Look at this [corrected] code:
print "Please enter the first name of a family member."
print "The choices are John, Jane, Jim, and scruffle."
text = raw_input()
if text == "John":
print "Hello, John"
elif text == "Jane":
print "Hello, Jane"
elif text == "Jim":
print "Hello, Jim"
elif text == "Scruffle":
print "RUFF!!"
else:
print "I don't know you, sorry!"
#3
Posted 15 October 2007 - 02:58 PM
v0id said:
First of all; the indents aren't showing, because you're not using the code-tags. Use them in your further posts.
There is four major problems in the code you posted.
1. input() is used for integers, and such, while raw_input() is used for text-input. Just think of it like: input() for numbers and raw_input() for strings.
2. Instead of using the compare-operator, ==, you're using the assignment operator, =. There's a big difference between these operators.
3. When your tries to compare in most of your if-statements, you're forgetting the double-quotes. These are necessary, or the interpreter will see them as variables - and you haven't declared those variable - which result in: error(s)
4. Languages like C++ are using curly brackets for statements, and such, while Python is using colons and indents. So, you need a ':' right after all the places where you're using a statement, e.g. if-statements.
Look at this [corrected] code:
There is four major problems in the code you posted.
1. input() is used for integers, and such, while raw_input() is used for text-input. Just think of it like: input() for numbers and raw_input() for strings.
2. Instead of using the compare-operator, ==, you're using the assignment operator, =. There's a big difference between these operators.
3. When your tries to compare in most of your if-statements, you're forgetting the double-quotes. These are necessary, or the interpreter will see them as variables - and you haven't declared those variable - which result in: error(s)
4. Languages like C++ are using curly brackets for statements, and such, while Python is using colons and indents. So, you need a ':' right after all the places where you're using a statement, e.g. if-statements.
Look at this [corrected] code:
print "Please enter the first name of a family member."
print "The choices are John, Jane, Jim, and scruffle."
text = raw_input()
if text == "John":
print "Hello, John"
elif text == "Jane":
print "Hello, Jane"
elif text == "Jim":
print "Hello, Jim"
elif text == "Scruffle":
print "RUFF!!"
else:
print "I don't know you, sorry!"
Thanks so much, but could you please clarify on #3?:o
Also with my revised code:
#small program to introduce members of the family
print "Please enter the first name of a family member.", " ", "the choices are john, jane, jim, and scruffle."
text = raw_input()
if text == "john"
print "this is john":
elif text == jane
print "this is jane":
elif text == jim
print "this is jim":
elif text == scruffle
print "RUFF!!":
else:
print "Please retype!"
I get this error:
#4
Posted 16 October 2007 - 03:17 PM
Before the explanation of #3, I'll help you with the "invalid syntax" error. You need to add a colon (:) in the end, right after "john" It will fix it. Look at my #4 in my last post.
To the #3.
Many programming languages (C, C++, C#, Java, Visual Basic, many LISP-dialects, etc.) and also Python, of course, uses special techniques to identify variables, strings, characters. It's different from language to language, but usually you're using single-quotes for characters, double-quotes for strings and nothing for variables. Try to pick up some tutorial, it will clear it up for you - much better than I tried - and you'll understand.
To the #3.
Many programming languages (C, C++, C#, Java, Visual Basic, many LISP-dialects, etc.) and also Python, of course, uses special techniques to identify variables, strings, characters. It's different from language to language, but usually you're using single-quotes for characters, double-quotes for strings and nothing for variables. Try to pick up some tutorial, it will clear it up for you - much better than I tried - and you'll understand.


Sign In
Create Account

Back to top









