Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Python

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-2007, 04:33 PM
hds272 hds272 is offline
Newbie
 
Join Date: Oct 2007
Posts: 4
Credits: 0
Rep Power: 0
hds272 is on a distinguished road
Default I need help!!!!

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!!"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 10-15-2007, 04:57 PM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,573
Last Blog:
CherryPy(thon)
Credits: 54
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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:
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!"
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
-
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
-
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

I'm always up for a chat, so feel free to contact me...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-15-2007, 05:58 PM
hds272 hds272 is offline
Newbie
 
Join Date: Oct 2007
Posts: 4
Credits: 0
Rep Power: 0
hds272 is on a distinguished road
Default

Quote:
Originally Posted by v0id View Post
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:
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?



Also with my revised code:
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:

Last edited by hds272; 10-15-2007 at 09:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-16-2007, 06:17 PM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,573
Last Blog:
CherryPy(thon)
Credits: 54
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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 view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
-
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
-
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

I'm always up for a chat, so feel free to contact me...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 04:45 AM.

Contest Stats

Xav ........ 1097.16
MeTh0Dz|Reb0rn ........ 986.37
morefood2001 ........ 850.04
John ........ 841.93
WingedPanther ........ 684.54
marwex89 ........ 638.26
Brandon W ........ 493.36
chili5 ........ 292.12
Steve.L ........ 188.37
orjan ........ 187.41

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads