Page 143 - TechPluse_C8_Flipbook
P. 143

print ( "First number is greater than second number " )
                          else :
                              print ( "Second number is greater than first number " )
                     2.  num = 3.4
                          if num > 0:
                              print("Positive number")
                          elif num == 0:
                              print(“Zero”)
                          else:
                              print("Negative number")
                     3.  x = 31
                          if x > 10:
                            print("Above ten")
                            if x > 20:
                              print("and also above 20!")
                            else:
                              print("but not above 20.")
                     4.  a = 200
                          b = 33
                          if b > a:
                            print("b is greater than a")
                          else:
                             print("b is not greater than a")
                     5.  x=1
                          sum=0
                          while(x<=10):
                              sum=sum+x
                               x=x+1
                          print (sum)
                     6.   fruits = [“apple”, ”banana”,”cherry”]
                          for x in fruits:
                              print(x)
                     7.  i = 2
                          while True:
                              if i%3 == 0:
                                  break
                              print(i)
                              i += 2
                     8.  i = 0
                          while i < 5:
                              print(i)
                              i += 1
                              if i == 3:
                                  break
                          else:
                              print(0)
                                                                Conditional and Looping Statements in Python         141
   138   139   140   141   142   143   144   145   146   147   148