Beispiel #1
0
"""Write a program to generate Fibonacci series of numbers.
    Starting numbers are 0 and 1,  new number in the series is generated by adding previous two numbers in the series.
  Example : 0, 1, 1, 2, 3, 5, 8,13,21,.....
   a) Number of elements printed in the series should be N numbers, Where N is any +ve integer.
   b) Generate the series until the element in the series is less than Max number.
"""
from Basics import Input

print("Problem Statement:", __doc__)

int1 = Input.fetchValidate('int', 1)[0]

a = 0
b = 1
arr1 = []
print(a, end=' ')
for x in range(1, int1 + 1):
    c = a + b
    if c <= int1:
        arr1.append(c)
    print(c, end=' ')
    a = b
    b = c

print("\nSeries less than %d is/are " % int1)
print(arr1, end=' ')
Beispiel #2
0
"""Create a list of 5 names and check given name exist in the List.
        a) Use membership operator ( IN ) to check the presence of an element.
        b) Perform above task without using membership operator.
        c) Print the elements of the list in reverse direction.
        List elements are ['perl', 'python', 'tcl', 'java', 'c']
"""
from Basics import Input

print("Problem Statement:", __doc__)

arg1 = Input.fetchValidate('str', 1)[0]

names = ['perl', 'python', 'tcl', 'java', 'c']

if arg1 in names:
    print("Element found using IN operator")
else:
    print("Element not found, used IN operator")

for y in range(0, 5):
    if names[y] == arg1:
        print("Element found using '==' operator")
        break
else:
    print("Element not found, used '==' operator")

print("Printing the array in reverse")
for z in range(4, -1, -1):
    print(names[z])
Beispiel #3
0
"""Write program to perform following:
     i) Check whether given number is prime or not.
    ii) Generate all the prime numbers between 1 to N where N is given number.
"""
from Basics import PrimeOdd, Input

print("Problem Statement:", __doc__)

int1, int2 = Input.fetchValidate('int', 2)

prim_obj = PrimeOdd(int1)

print("The number %d " % int1, prim_obj.prime())
print("The prime numbers from 2 to %d are " % int2)

if int2 <= 1:
    print("No prime numbers")
for x in range(2, int2 + 1):
    # prime numbers are greater than 1
    if x > 1:
        for i in range(2, x):
            if (x % i) == 0:
                break

        else:
            print(x, end=' ')
Beispiel #4
0
"""Write a program to read string and print each character separately.
    a) Slice the string using slice operator [:] slice the portion the strings to create a sub strings.
    b) Repeat the string 100 times using repeat operator *
    c) Read strig 2 and  concatenate with other string using + operator.
"""

from Basics import SliceConcat, Input

print("Problem Statement:", __doc__)

str1, str2 = Input.fetchValidate('str', 2)

str_obj = SliceConcat(str1)
print("==============================================")
print("Printing each character of string1 seperately")
str_obj.Printall()

print("\n==============================================")
str_obj.Slicing()
print("==============================================")
cl
print("Repeating the string 100 times")
str_obj.Repeat(100)
print("==============================================")

if str2:
    print("Concatinated string 1 and 2")
    str_obj.Concat(str2)
    print("==============================================")
Beispiel #5
0
"""Create a tuple with at least 10 elements in it
       print all elements
       perform slicing
       perform repetition with * operator
       Perform concatenation wiht other tuple.
"""

from Basics import SliceConcat, Input

print("Problem Statement:", __doc__)

tup2 = Input.fetchValidate('tuple', 1)[0]
tup1 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

str_obj = SliceConcat(tup1)
print("==============================================")
print("Printing elements of the tuple1")
str_obj.Printall()

print("\n==============================================")
str_obj.Slicing()
print("==============================================")

print("Repeating the tuple 10 times ")
str_obj.Repeat(10)
print("==============================================")

if tup2:
    print("Concatinated 2 tuples")
    str_obj.Concat(tup2)
    print("==============================================")
Beispiel #6
0
""" Write a program to find  given number is prime or not
"""

from Basics import PrimeOdd, Input

print("Problem Statement:", __doc__)
a = Input.fetchValidate('int', 1)

obj1 = PrimeOdd(a[0])

print("The number '%s' is " % a[0], obj1.prime())
Beispiel #7
0
     ( minimum 10 entries in each list ) and perform following operations
     a) Print all names on to screen
     b) Read the index from the  user and print the corresponding name from both list.
     c) Print the names from 4th position to 9th position
     d) Print all names from 3rd position till end of the list
     e) Repeat list elements by specified number of times ( N- times, where N is entered by user)
     f)  Concatenate two lists and print the output.
     g) Print element of list A and B side by side.( i.e.  List-A First element ,  List-B First element )

"""

from Basics import SliceConcat, Input

print("Problem Statement:", __doc__)

arg1, arg2 = Input.fetchValidate('int', 2)

empid = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
empname = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

id_obj = SliceConcat(empid)
name_obj = SliceConcat(empname)

print("Printing all employee names: ")
name_obj.Printall()

print("\n-------------------------------------------------")
print("The employee id and name for the index %d is " % arg1, "id: ",
      empid[arg1], " name:", empname[arg1])

print("-------------------------------------------------")
Beispiel #8
0
"""Create a list with at least 10 elements in it
       print all elements
       perform slicing
       perform repetition with * operator
       Perform concatenation wiht other list.
"""

from Basics import SliceConcat, Input

print("Problem Statement:", __doc__)

lst2 = Input.fetchValidate('list', 1)[0]
lst1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

str_obj = SliceConcat(lst1)
print("==============================================")
print("Printing elements of the list1")
str_obj.Printall()

print("\n==============================================")
str_obj.Slicing()
print("==============================================")

print("Repeating the list 10 times ")
str_obj.Repeat(10)
print("==============================================")

if lst2:
    print("Concatinated List")
    str_obj.Concat(lst2)
    print("==============================================")
Beispiel #9
0
#import cmath
"""Write program to Add , subtract, multiply, divide 2 complex numbers.
"""

from Basics import Math, Input

print("Problem Statement:", __doc__)

cn1, cn2 = Input.fetchValidate('str', 2)
op = input("Enter the operation 'add' or 'sub' or 'mul' or 'div': ").strip()

obj1 = Math(complex(cn1), complex(cn2))

if op == "add":
    print("Addition of two numbers is ", obj1.add())
if op == "sub":
    print("Subtraction of two numbers (absolute) is ", obj1.sub())
if op == "mul":
    print("Multiplication of two numbers is ", obj1.mul())
if op == "div":
    print("Division of two numbers is ", obj1.div())
Beispiel #10
0
"""Write a program to find the biggest of 3 numbers ( Use If Condition )
"""
from Basics import Math, Input

print("Problem Statement:", __doc__)

list_of_num = Input.fetchValidate('int', 3)
great_val = Math.greater(list_of_num)

print("Greatest among 3 integers is ", great_val)