Jump to content


Photo

Chapter 1 - Else(syntaxerror)


  • Please log in to reply
3 replies to this topic

#1 mocellin

mocellin

    New Member

  • Members
  • Pip
  • 1 posts

Posted 05 April 2014 - 09:25 AM

The else for each if below, does not compile as expected. If I do remove the else, does compile without error.

for each_item in movies:
if isinstance(each_item, list):
for nested_item in each_item:
if isinstance (nested_item, list):
for deeper_item in nested_item:
else: print(nested_item) else: print (each_item)

#2 wunderwaffe

wunderwaffe

    Active Member

  • Members
  • PipPip
  • 26 posts

Posted 15 April 2014 - 03:27 AM

The else for each if below, does not compile as expected. If I do remove the else, does compile without error.

for each_item in movies:
if isinstance(each_item, list):
for nested_item in each_item:
if isinstance (nested_item, list):
for deeper_item in nested_item:
else: print(nested_item) else: print (each_item)


You've missed a print statement.

for each_item in movies:
	if isinstance(each_item, list):
		for nested_item in each_item:
			if isinstance (nested_item, list):
				for deeper_item in nested_item:
					print(deeper_item)
			else: print(nested_item)
	else:
		print (each_item)


#3 MinerAeros

MinerAeros

    New Member

  • Members
  • Pip
  • 2 posts

Posted 02 December 2014 - 06:05 AM



I am also having problems with this exercise!

I wrote the code and it executed perfectly, but once I added the comments, saved it and tried to run it, I kept getting errors saying inconsistent use of Tabs and Spaces.

My code is shown in the attachment. Any thoughts?

Capture.PNG
Cheers

Neville

#4 MinerAeros

MinerAeros

    New Member

  • Members
  • Pip
  • 2 posts

Posted 03 December 2014 - 04:38 AM



I am also having problems with this exercise!

I wrote the code and it executed perfectly, but once I added the comments, saved it and tried to run it, I kept getting errors saying inconsistent use of Tabs and Spaces.

My code is shown in the attachment. Any thoughts?

Capture.PNG
Cheers

Neville


I managed to resolve the issue by using # for the comments instead of the triple quotation marks! But I'd really like to know why this works and triple quotes don't? :blink:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users