jueves, 26 de marzo de 2015

#Mastery18 nesting of conditonal statements:

in other words putting an if inside an if.
you can see in this program how it creates a hole new conditional statement if the first conditon is not met (an if inside an else).

see here:
def gcd(x,y):
if (x==y):
ans=x
else:
if(x>y):
ans=gcd((x-y),y)
else:
ans=gcd(x,(y-x))
return ans

If the first condicional is not met (the values are not the same) then ,by definition, thay are different, but they can be differnt in 2 ways (greater than and lesser than...), so a new condition has to be made. 

Its really easy, and probably you would be doing it without noticing, the import thing is that all conditionals result on something, and make shure to close them all and dont loose track. 

No hay comentarios:

Publicar un comentario