![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 56
Rep Power: 3
![]() |
Syntax error
Hey can someone help me correct this code .
This is the part where it says there is a sytax error . elif guess < number:
print "Guess is smaller than number"And this is the full code . #This program uses the if else if program to create the high low game
number = 30
guess = 0
while guess!=number: #while guess!=number its detonated
guess = input("Guess : ") #as the guess again .
if guess > number:
print "Guess is greater than number"
elif guess < number:
print "Guess is smaller than number"
print "Just right!"Thanx for help . |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Aug 2005
Location: Hiding from... them...
Posts: 110
Rep Power: 4
![]() |
Indentation matters. The "elif" needs to be at the same indentation level as the "if."
Don't you hate it when you get nailed by something like that? |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
You'll also want to add in an "else" before the final line of code, or else :
print "Just right!" , will execute when : print "Guess is smaller than number" , does. #This program uses the if else if program to create the high low game
number = 30
guess = 0
while guess!=number: # while guess!=number its detonated
guess = input("Guess : ") # as the guess again
if guess > number:
print "Guess is greater than number"
elif guess < number:
print "Guess is smaller than number"
else:
print "Just right!"I believe that's what you want. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
i think indentation is important for readability and style...but for partitioning code blocks? just switching text editors could fuck up your program. that's stupid. i never got that about python.
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Oct 2005
Posts: 56
Rep Power: 3
![]() |
Wtf..its so sensitive ? lol,..Anyway thanx for helping .
|
|
|
|
|
|
#6 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
Personally, I've never had any problems with Python indentation. |
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
if guess > number:
print "Guess is greater than number"
elif guess < number:
print "Guess is smaller than number"
print "Just right!" if (guess > number) {
System.out.println("Guess is greater than number");
else if (guess < number) {
print "Guess is smaller than number"
print "Just right!"
}
} |
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Aug 2005
Location: Hiding from... them...
Posts: 110
Rep Power: 4
![]() |
Yeah, I'm with Arevos- it's never been a problem. I love not having curly braces all over the place.
__________________
:wq |
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Somebody is forgetting their ;;;;;;;;;;; in the Java code! Not only is Java loaded with {}{}{}{}{}, but also with ;;;;;; ! I prefer indentations, have to do it anyway so people can read the code!
Always thought that was the neatest thing about Python.
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Nov 2005
Posts: 1
Rep Power: 0
![]() |
elif and if must be in same indent if they are to recieve equal weightage
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|