What is my error here?


#1

I am missing something that outputs this code wrong. I have the SYNTAX messed up somewhere…

"""This code is a test of my knowledge!"""
Sandwich = 17
Butter = 50
Condom = 49
if Sandwich == Condom
	print "This should be the wrong response."
	else print "This should be the valid response to the code at hand."

#2

you have an indent issue. else should have the same indent level as if


#3

Could you correct it and show me, I am confused as heck! D;


#4

understanding indent(ion) is crucial in python, given it determines nesting (what is nested in if clause for example):

if True:
    print "i am nested inside the if clause"

print "i am nested outside the if clause"

you nested your else inside your if clause, which causes problem, given else needs to be outside/after your if clause, given it needs to run when if evaluates to false


#5

Okay, haven’t got to that part of the Python training just yet. Thank you anyway!!! You’re a big help.


#6

you use if and else, to use them, you must understand indent(ion), see the docs:

https://docs.python.org/2.0/ref/indentation.html


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.