Thursday, 5 January 2017

PYTHON -Loops & Conditions

IF STATEMENT:


a=10
if a>0:
  print("a is greater than zero, because a value is",a)


IF.. ELSE STATEMENT

a=0
if a<10:
  print("a is greater than zero, because a value is",a)
else:
  print ("a is greater than zero, because a value is",a)

IF..ELIF..ELSE

a=1
b=2
c=3
if a>b and a>c:
  print("a is greater than b and c")
elif b>c and b>a:
  print("b is greater than a and c")
elif c>a and c>b:
  print("c is greater than a and b")
else:
  print("All are equal")


WHILE WITH NESTED IF:

n = 1
while n <= 20:
    if n % 2 == 0:
        print (n," ")
    n = n + 1
print ("there, done.")



WHILE WITH NESTED WHILE:


n = 1
while n<=5:
  m=1
  while m<=n:
    print(m,"\t")
    m=m+1
  n=n+1
  print("\n")
print("done")
 


No comments:

Post a Comment