1. Develop Python Code to print first 10 numbers.
##Using 'for' loop
a = 11
for i in range(1,a):
print(i)

##Using 'while' loop
a = 1
while a < 11:
print(a)
a = a+1
    2. Develop Python Code to print 10 to 0 in horizontal way.
    ##Using 'for' loop
    a = 10
    b = ""for i in range(a,0,-1):
    b = b+" "+str(i)
    print(i,end=" ")
    print(b)

    ##Using 'while' loop
    a = 10
    while a > 0:
    print(a,end=" ")
    a = a-1
      3. Develop Python Code to read any number and print numbers up to it, printing numbers should be tab separated and horizontal.
      ##Using 'for' loop
      a = int(input("Enter any number :"))
      for i in range(1,a+1):
      print(i,end=" ")

      ##Using 'while' loop
      a = int(input("Enter any number :"))
      b = 1
      while b <= a:
      print(b,end=" ")
      b = b+1
        4. Develop Python Code to read any number and print sum, average of numbers up to it.
        ##Using 'for' loop
        a = int(input("Enter any Number :"))
        b = 0
        for i in range(1,a+1):
        b = b+i
        print("Sum of N Numbers is :",b,"Average of the N Numbers is :",(b/i))

        ##Using 'while' loop
        a = c = int(input("Enter any Number :"))
        b = 0
        while a > 0:
        b = b+a
        a = a-1
        print("Sum of N Numbers is :",b,"Average of the N Numbers is :",(b/c))
          5. Develop Python Code to read a number and a string, print the name up to read number times.
          ##Using 'for' loop
          a = int(input("Enter any Number :"))
          b = input("Enter any String :")
          for i in range(a):
          print(b)

          ##Using 'while' loop
          a = int(input("Enter any Number :"))
          b = input("Enter any String :")
          while a > 0:
          print(b)
          a = a-1
            6. Develop Python Code for an infinite loop using while construct.
            ##Using 'while' loop
            while 2 > 1:
            print("Hello")
              7. Develop Python Code to print small alphabets from a to z.
              ##Using 'for' loop
              a = ord("a")
              for i in range(a,a+26):
              print(chr(i))

              ##Using 'while' loop
              a = ord("a")
              b = a+26
              while a < b:
              print(chr(a))
              a = a+1
                8. Develop Python Code to print capital alphabet form Z to A using while loop.
                ##Using 'for' loop
                a = ord("Z")
                for i in range(a,a-26,-1):
                print(chr(i))

                ##Using 'while' loop
                a = ord("Z")
                b = a-26
                while a > b:
                print(chr(a))
                a = a-1
                  9. Develop Python Code to read any number and print even, odd numbers up to it.
                  ##Using 'for' loop
                  a = int(input("Enter any Number :"))
                  for i in range(1,a+1,2):
                  print(i,end=" ")
                  print("\n")
                  for i in range(2,a+1,2):
                  print(i,end=" ")

                  ##Using 'while' loop
                  a = int(input("Enter any Number :"))
                  b = 1
                  c = 2
                  while b <= a:
                  print(b,end=" ")
                  b = b+2
                  while c <= a:
                  print(c,end=" ")
                  c = c+2
                    10. Develop Python Code to read any number and print its multiplication table up to 10 times.
                    ##Using 'for' loop
                    a = int(input("Enter any Number :"))
                    for i in range(1,11):
                    print(str(a)+"X"+str(i)+"="+str(a*i))

                    ##Using 'while' loop
                    a = int(input("Enter any Number :"))
                    b = 1
                    while b < 11:
                    print(str(a)+"X"+str(b)+"="+str(a*b))
                    b = b+1
                      11. Develop Python Code to read any number and print its factorial.
                      ##Using 'for' loop
                      a = int(input("Enter any Number :"))
                      b = 1
                      for i in range(1,a+1):
                      b = b*i
                      print(b)

                      ##Using 'while' loop
                      a = int(input("Enter any Number :"))
                      b = 1
                      while a > 0:
                      b = b*a
                      a = a-1
                      print(b)
                        12. Develop Python Code to read two numbers, second number must be greater than first number and print numbers in between numbers.
                        ##Using 'for' loop
                        a = int(input("Enter any Number :"))
                        b = int(input("Enter any Number :"))
                        for i in range(a+1,b):
                        print(i)

                        ##Using 'while' loop
                        a = int(input("Enter any Number :"))
                        b = int(input("Enter any Number :"))
                        while a < b-1:
                        a = a+1
                        print(a)
                          13. Develop Python Code to print multiples of 3 and 7 up to some entered number.
                          ##Using 'for' loop
                          a = int(input("Enter any Number :"))
                          for i in range(3,a,3):
                          print(i,end=" ")
                          for i in range(7,a,7):
                          print(i,end=" ")

                          ##Using 'while' loop
                          a = int(input("Enter any Number :"))
                          c , d = 3 , 7
                          while a >= c:
                          print(c,end=" ")
                          c = c+3
                          while a >= d:
                          print(d,end=" ")
                          d = d+7
                            14. Develop Python Code to read any sting and print all its letters separately.
                            ##Using 'for' loop
                            a = input("Enter any string :")
                            for i in a:
                            print(i)
                              15. Develop Python Code to read five numbers from keyboard, print their sum, average.
                              ##Using 'for' loop
                              a = 0
                              for i in range(5):
                              b = int(input("Enter any Number :"))
                              a = a+b
                              print("Sum of 5 Numbers is :"+str(a)+"Average of 5 Numbers is :"+str(a/5))

                              ##Using 'while' loop
                              a = 0
                              b = 5
                              while b > 0:
                              c = int(input("Enter any Number :"))
                              a = a+c
                              b = b-1
                              print("Sum of 5 Numbers is :"+str(a)+", Average of 5 Numbers is :"+str(a/5))
                                16. Develop Python Code to read any number and print digits of that number.
                                ##Using 'for' loop
                                a = int(input("Enter any Number :"))
                                for i in range(len(str(a))):
                                print("1"+"0"*i+"'s digit is",a%10)
                                a = a//10

                                ##Using 'while' loop
                                a = int(input("Enter any Number :"))
                                b = 0
                                while a > 0:
                                print("1"+"0"*b+"'s digit is",a%10)
                                a = a//10
                                b = b+1
                                  17. Develop Python Code to print the below pattern using while loop.
                                  #
                                  # #
                                  # # #
                                  # # # #
                                  # # # # #
                                  ##Using 'while' loop
                                  a = 1
                                  while a < 6:
                                  print("# "*a)
                                  a = a+1
                                    18. Develop Python Code to read any number and count the digits.
                                    ##Using 'for' loop
                                    a = int(input("Enter any Number :"))
                                    for i in range(a):
                                    a = a//10
                                    if a == 0:
                                    break
                                    print(i+1)

                                    ##Using 'while' loop
                                    a = int(input("Enter any Number :"))
                                    b = 0
                                    while a > 0:
                                    b = b+1
                                    a = a//10
                                    print(b)
                                      19. Develop Python Code to read any number and print the reverse of it.
                                      ##Using 'for' loop
                                      a = int(input("Enter any Number :"))
                                      for i in range(len(str(a))):
                                      print(a%10,end="")
                                      a = a//10

                                      ##Using 'while' loop
                                      a = int(input("Enter any Number :"))
                                      while a > 0:
                                      print(a%10,end="")
                                      a = a//10
                                        20. Develop Python Code to print numbers 1-20 numbers using loop and random function.
                                        ##Using 'for' loop
                                        import random
                                        a = int(input("Enter any Number :"))
                                        for i in range(a):
                                        print(random.randint(1,20))

                                        ##Using 'while' loop
                                        import random
                                        a = int(input("Enter any Number :"))
                                        while a > 0:
                                        print(random.randint(1,20))
                                        a = a-1
                                          21. Develop Python Code to read any number and print sum of digits.
                                          ##Using 'for' loop
                                          a = int(input("Enter any Number :"))
                                          b = 0
                                          for i in range(len(str(a))):
                                          b = b+(a%10)
                                          a = a//10
                                          print(b)

                                          ##Using 'while' loop
                                          a = int(input("Enter any Number :"))
                                          b = 0
                                          while a > 0:
                                          b = b+(a%10)
                                          a = a//10
                                          print(b)
                                            22. Develop Python Code to read any number and print the product of digits.
                                            ##Using 'for' loop
                                            a = int(input("Enter any Number :"))
                                            b = 1
                                            for i in range(len(str(a))):
                                            b = b*(a%10)
                                            a = a//10
                                            print(b)

                                            ##Using 'while' loop
                                            a = int(input("Enter any Number :"))
                                            b = 1
                                            while a > 0:
                                            b = b*(a%10)
                                            a = a//10
                                            print(b)
                                              23. Develop Python Code to read any number and print square and cube of numbers up to it.
                                              ##Using 'for' loop
                                              a = int(input("Enter any Number :"))
                                              for i in range(1,a+1):
                                              print(str(i)+" Square is :"+str(i**2)+" ,Cube is "+str(i**3))

                                              ##Using 'while' loop
                                              a = int(input("Enter any Number :"))
                                              b = 1
                                              while a > 0:
                                              print(str(b)+" Square is :"+str(b**2)+" ,Cube is "+str(b**3))
                                              a = a-1
                                              b = b+1
                                                24. Develop Python Code to print factors of a number.
                                                ##Using 'for' loop
                                                a = int(input("Enter any Number :"))
                                                for i in range(1,a+1):
                                                if a % i == 0:
                                                print(i)

                                                ##Using 'while' loop
                                                a = int(input("Enter any Number :"))
                                                b = 1
                                                while b <= a:
                                                if a % b == 0:
                                                print(b)
                                                b = b+1
                                                  25 Develop Python Code to read a number and a power, find number power without using ** (power) operator.
                                                  ##Using 'for' loop
                                                  a = int(input("Enter any Number :"))
                                                  c = a
                                                  b = int(input("Enter Power :"))
                                                  for i in range(b-1):
                                                  a = a*c
                                                  print(a)

                                                  ##Using 'while' loop
                                                  a = int(input("Enter any Number :"))
                                                  c = a
                                                  b = int(input("Enter Power :"))
                                                  while b > 1:
                                                  a = a*c
                                                  b = b-1
                                                  print(a)
                                                    26. Develop Python Code to print Fibonacci series up to N terms.
                                                    ##Using 'for' loop
                                                    a = int(input("Enter any Number :"))
                                                    b = 0
                                                    c = 1
                                                    for i in range(a):
                                                    print(c)
                                                    b,c = c,b+c

                                                    ##Using 'while' loop
                                                    a = int(input("Enter any Number :"))
                                                    b = 0
                                                    c = 1
                                                    while a > 0:
                                                    print(c)
                                                    b,c = c,b+c
                                                    a = a-1
                                                      27. Develop Python Code to print Fibonacci series up to some number.
                                                      ##Using 'for' loop
                                                      a = int(input("Enter any Number :"))
                                                      b = 0
                                                      c = 1
                                                      for i in range(a):
                                                      print(c)
                                                      b,c = c,b+c
                                                      if c > a :
                                                      break

                                                      ##Using 'while' loop
                                                      a = int(input("Enter any Number :"))
                                                      b = 0
                                                      c = 1
                                                      while a > 0:
                                                      print(c)
                                                      a = a-1
                                                      if c >= a :
                                                      break
                                                      b,c = c,b+c
                                                        28. Develop Python Code to print read number and print binary form of it.
                                                        ##Using 'for' loop
                                                        a = b = int(input("Enter any Number"))
                                                        c = ""
                                                        for i in range(a):
                                                        c = str(a%2)+c
                                                        a = a//2
                                                        if a == 0:
                                                        break
                                                        print("Entered Number is :"+str(b)+"\nBinary form is :"+str(c))

                                                        ##Using 'while' loop
                                                        a = b = int(input("Enter any Number :"))
                                                        c = ""
                                                        while a:
                                                        c = str(a%2)+c
                                                        a = a//2
                                                        print("Entered Number is :"+str(b)+"\nBinary form is :"+str(c))
                                                          29. Develop Python Code to print 1’s complement of a binary number.
                                                          ##Using 'for' loop
                                                          a = input("Enter any Binary Number :")
                                                          b = ""
                                                          for i in range(len(a)):
                                                          if a[i] == "0":
                                                          b = b+"1"
                                                          else:
                                                          b = b+"0"
                                                          print("1's complement form is :"+b)

                                                          ##Using 'while' loop
                                                          a = input("Enter any Binary Number :")
                                                          b = ""
                                                          c = 0
                                                          while c < len(a):
                                                          if a[c] == "0":
                                                          b = b+"1"
                                                          else:
                                                          b = b+"0"
                                                          c = c+1
                                                          print("1's complement form is :",b)
                                                            30. Develop Python Code to read any string and print all letters by skipping vowels.
                                                            ##Using 'for' loop
                                                            a = input("Enter any String :")
                                                            for i in a:
                                                            if i != "a" and i != "e" and i != "i" and i != "o" and i != "u":
                                                            print(i,end="")

                                                            ##Using 'while' loop
                                                            a = input("Enter any String :")
                                                            b = 0
                                                            while a:
                                                            if a[b] != "a" and a[b] != "e" and a[b] != "i" and a[b] != "o" and a[b] != "u":
                                                            print(a[b],end="")
                                                            b = b+1
                                                            if b == len(a):
                                                            break
                                                              31. Develop a logic based code to print the below series using loop.
                                                              2,4,8,16,32,64,128
                                                              ##Using 'for' loop
                                                              a = 7
                                                              for i in range(1,a+1):
                                                              print(2**i,end=",")

                                                              ##Using 'while' loop
                                                              a = 1
                                                              while a <= 7:
                                                              print(2**a,end=",")
                                                              a = a+1
                                                                32. Develop a logic based code to print the below series using loop.
                                                                3,5,9,17,33,65,129
                                                                ##Using 'for' loop
                                                                a = 7
                                                                for i in range(1,a+1):
                                                                print((2**i)+1,end=",")

                                                                ##Using 'while' loop
                                                                a = 1
                                                                while a <= 7:
                                                                print((2**a)+1,end=",")
                                                                a = a+1
                                                                  33. Develop a logic based code to print the below series using loop.
                                                                  9,28,65,126,217,344.
                                                                  ##Using 'for' loop
                                                                  a = 7
                                                                  for i in range(2,a+1):
                                                                  print((i**3)+1,end=",")

                                                                  ##Using 'while' loop
                                                                  a = 2
                                                                  while a <= 7:
                                                                  print((a**3)+1,end=",")
                                                                  a = a+1
                                                                    34. Develop a logic based python to evaluate the below.
                                                                    X0+X1+X2+X3+X4+........+Xn
                                                                    ##Using 'for' loop
                                                                    ##for printing N terms
                                                                    a = int(input("Enter any Number :"))
                                                                    b = "X**0"
                                                                    for i in range(1,a+1):
                                                                    b = b+"+X**"+str(i)
                                                                    print(b)
                                                                    ##for printing the value
                                                                    x = int(input("Enter X value :"))
                                                                    n = int(input("Enter N value :"))
                                                                    c = 0
                                                                    for i in range(n+1):
                                                                    c = c+x**i
                                                                    print(c)

                                                                    ##Using 'while' loop
                                                                    ##for printing N terms
                                                                    a = int(input("Enter any Number :"))
                                                                    b = "X**0"
                                                                    c = 1
                                                                    while a > 0:
                                                                    b = b+"+X**"+str(c)
                                                                    c = c+1
                                                                    a = a-1
                                                                    print(b)
                                                                    ##for printing the value
                                                                    x = int(input("Enter X value :"))
                                                                    n = int(input("Enter N value :"))
                                                                    c = 0
                                                                    while n >= 0:
                                                                    c = c+x**n
                                                                    n = n-1
                                                                    print(c)

                                                                      *Questions Prepared by--Srikanth.D

                                                                      Mentor in IT,Dept of IT,RGUKT-SRIKAKULAM
                                                                      duppada8@rguktsklm.ac.in

                                                                        34

                                                                        Projects

                                                                        300

                                                                        Minutes Of Support

                                                                        5

                                                                        Hard Worker