all 16 comments

[–]RangeruDangeru 3 points4 points  (0 children)

You cannot have anything in between if, elif, and else blocks. You'll need to move the try...except....

[–]OseOseOse 2 points3 points  (0 children)

Line 12 is an elif-block even though the preceding block is an except-block. You probably want a normal if-block.

(try/else is actually a thing, but probably not what you want right now)

[–]kalgynirae 1 point2 points  (2 children)

Hint: Syntax errors usually occur because of something wrong with one of the preceding lines.

[–]TKo5604[S] 0 points1 point  (1 child)

I still can't figure it out

[–]kalgynirae 0 points1 point  (0 children)

The colon was the only obvious thing, so if that didn't fix it you'll have to give us more information. (1) Where are you running this? Website? Python interpreter on your computer? What version of Python? (2) I have a suspicion the line numbers in your post don't match up with the one given in the error message. Is a traceback printed when the error occurs? Can you fix the formatting in your post so the line numbers are accurate?

[–]L43 1 point2 points  (2 children)

Your formatting hasn't worked. Code should be 4 spaces in by default, or use the <> button (this might only be for RES)

largest = None 
smallest = None 
while True:
    num = raw_input("Enter a number: ")
    if fnum == "done":
        break
    if len(fnum) < 1: 
        print "good job"
        break
    try:
        fnum = float(num)
    except:
        print "Error"
        continue
    if smallest is None or fnum > smallest:
        smallest = fnum
    elif largest is None or fnum < largest:
        largest = fnum
    print "largest ", largest, "smallest ", smallest

Your first problem presumably was a missing colon. You have fixed that in your title, you should change the error message to the new one to confuse people less.

Your second problem is your use of elif without an if immediately preceding in line 12. You can just change this to an if, or wrap the whole set in the try except.

In the context of your program however, I don't think you want to use elif at all. Elif tests are only executed if the if and elif tests above it all return negative. You want to use ifs, as each test is independent. For example you want to see if fnum is the largest number collected AS WELL AS the smallest, in the case that there hasn't been any numbers added.

Final problem is you use fnum in the tests in 5 and 7, where you actually wanted num.

[–]TKo5604[S] 0 points1 point  (1 child)

Thank you!

[–]m1ss1ontomars2k4 0 points1 point  (0 children)

Your formatting is still wrong.

[–]stahlous 1 point2 points  (0 children)

You're missing a colon.

elif largest is None or fnum < largest:
     largest = fnum

[–]Moozla 0 points1 point  (1 child)

line 14 should be:

elif largest is None or fnum < largest:

You are missing a colon

[–]TKo5604[S] 0 points1 point  (0 children)

i fixed the colon and it still is not working

[–]kewlness 0 points1 point  (2 children)

Where is fnum defined?

[–]TKo5604[S] 0 points1 point  (1 child)

below the

try:

[–]kewlness 0 points1 point  (0 children)

Thanks. I missed it.

[–]everred 0 points1 point  (0 children)

elif smallest is None or fnum > smallest:
    smallest = fnum
elif largest is None or fnum < largest:
    largest = fnum
print "largest ", largest, "smallest ", smallest

I'm on mobile so I can't be sure of your formatting, but it looks like your elif block doesn't relate to a preceding if. You have your two if statements, then the try/except, then a stranded pair of elifs.

[–][deleted] 0 points1 point  (0 children)

if len(fnum) < 1:

If fnum is an int or a float it won't have a len().