for line in range(50):
def show_table():
if len(table) == 0:
print('There are no cards on the table.')
else:
for card in range(len(table)):
print names[table[card][0]] + ' played a ' + str(table[card][1]) + '.'
for line in range(50): def show_table(): if len(table) == 0: print(‘There are no cards
Share
The first problem is that the colon goes at the end of the if condition, not after the word
if. So:Or, better:
However, testing this with both Python 2.7 and 3.3, I think you should actually be getting a SyntaxError, with the little caret pointing at the excess colon, rather than an error about indentation.
Which implies that the actual error is that the line above it does something wrong as well.
The next problem is that you can only use the one-liner shortcut with one colon, not two, so this:
Is just going to confuse the compiler. You really should break this up into idiomatic Python, rather than trying to see what you can get away with:
I’m not sure why you want to define a new function for each of 50 lines, and then never call that function, but this will at least be something legal… almost.
The last problem is this:
First,
printisn’t a statement in Python 3.3, it’s a regular old function, so you have to call it with arguments. Second, that?at the end doesn’t seem to be attached to anything it could reasonably be attached to, so it’s probably a stray typo that needs to be fixed. So:Looking at the raw version of what you pasted into your edited question—this is just a guess, because you didn’t paste it as code—it looks like there may be two more problems.
First, your first
forline is indented 1 column. When you later come back to column 0, that’s counted as two dedents, not one.Second, the
def show_table():line is indented to column 8, but the next thing after it is back to column 0. Maybe you wanted an empty function here? If so, that’s not legal; in Python, functions can never be empty. But you can get the same effect with thepassstatement: