class Birth_Date:
    def __init__(self):
        self.name = list()
        self.dob = list()
        self.util = UtilityDataStructures()

    def sayhi(self):
        print('hi')

    def take_input(self):
        # print("Enter the name")
        # string = input()
        # while(not self.util.is_string(string)):
        #     string = input()
        # self.name.append(string)
        # print(self.name)
        # print('Enter date of birth')
        # try:
        #     dob = dt(input())
        # except Exception:
        #     print("Not a proper input please try again")
        # print(dob)

        print("Enter a number")
        num = self.util.get_positive_integer()
        print(num)
from Utility.UtilityDataStructures import UtilityDataStructures

util = UtilityDataStructures()
flag: bool = True
while flag:

    try:
        list1 = [[10, 20], [40], [30, 56, 25], [10, 20], [33], [40]]
        list2 = []
        print(list1)
        # iterate through each element in the list
        for counter in range(list1.__len__()):
            # for the items after the current element iterated by the outer loop
            for counter2 in range(counter + 1, list1.__len__()):
                if util.equalsList(list1[counter], list1[counter2]):
                    list1.remove(list1[counter2])
        print(list1)
    except IndexError:
        print(list1)
    except Exception as exep:
        print("Process stopped because %s" % exep)
    print("To exit press 0 else press any other number")
    if input() == 0:
        flag = False
        prob_ace = self.ace / self.cards
        print(
            "The probability of getting an Ace after a king is taken is {}/{} that is {}"
            .format(self.ace, self.cards, prob_ace))

    def ace_After_Ace(self):
        self.ace -= 1
        self.cards -= 1
        print(
            "The probability od getting an ace after first getting an ace is {}/{} that is {}"
            .format(self.ace, self.cards, self.ace / self.cards))


try:
    card_object = Cards()
    util = UtilityDataStructures()
    string_list = ("Ace independent", "Ace after King", "Ace after Ace")
    num_input = 1
    while num_input != 0:
        for counter in range(0, len(string_list)):
            print("for {} press {}".format(string_list[counter], counter + 1))
        print("and press 0 to exit")
        num_input = util.get_positive_integer()
        if num_input == 1:
            card_object = Cards()
            card_object.ace_In_Pack_Of_Cards()
        elif num_input == 2:
            card_object = Cards()
            card_object.ace_After_King()
        elif num_input == 3:
            card_object = Cards()
from Utility.UtilityDataStructures import UtilityDataStructures
util = UtilityDataStructures()
flag: bool = True

try:

    dictnew = dict()
    dict1 = {0: 11, 1: 13}
    dict2 = {2: 12, 3: 16}
    dict3 = {4: 14, 5: 17}
    # storing the elements in the dictionary
    dictnew = dict1.copy()
    dictnew.update(dict2)
    dictnew.update(dict3)
    print("printing as items")
    while flag:
        for items in dictnew.items():
            print(items)

        print("Enter the key to be deleted")
        num = util.get_integer()
        # deleting the element from the dictionary
        try:
            dictnew.__delitem__(num)
            if len(dictnew) > 0:
                print(dictnew)
            else:
                print("dictionary empty")
        except KeyError:
            print('Key not found')
        print("To exit press 0 else press any other number")
from Utility.UtilityDataStructures import UtilityDataStructures


class Probability_Random_Number:
    def __init__(self):
        self.list_numbers = [x for x in range(2, 8)]

    def getting_probability(self, point_x):
        probability = self.list_numbers.count(point_x) / len(self.list_numbers)
        print("The probability to find {} in the set {} is {} ".format(point_x, self.list_numbers, probability))


try:
    probability_object = Probability_Random_Number()
    util = UtilityDataStructures()
    flag: bool = True
    while flag:
        print("Enter the number to find probability in the range 2 - 7 ")
        probability_object.getting_probability(util.get_integer())
        print("To exit press 0 else press any other number")
        if input() == 0:
                    flag = False
except Exception as e:
        print("Process stopped because %s" % e)
from Utility.UtilityDataStructures import UtilityDataStructures
util = UtilityDataStructures()
flag: bool = True
while flag:

    try:
        list1 = []
        print("Enter the number of entries")
        num_input = util.get_positive_integer()
        for counter in range(0, num_input):
            list1.append(input("Enter the string"))
            # calling function to get the length of the longest string
        print("length of the longest string is ", util.longest_string(list1))
    except Exception as e:
        print("Process stopped because %s" % e)
    print("To exit press 0 else press any other number")
    if input() == 0:
        flag = False
from Utility.UtilityDataStructures import UtilityDataStructures
util = UtilityDataStructures()
flag: bool = True
while flag:

    try:
        dict1 = {'': ''}
        dict1.clear()
        print("Enter the number")
        inputnum = util.get_positive_integer() + 1
        # storing the values in the dictionary
        dict1 = {(counter, counter * counter)
                 for counter in range(1, inputnum)}
        print(dict1)
        print("To exit press 0 else press any other number")
        if input() == 0:
            flag = False
    except Exception as e:
        print("Process stopped because %s" % e)
Example #8
0
class Object_Oriented_Problems:
    util = UtilityDataStructures()

    def __init__(self):
         print()

    def read_from_file(self, file_name):
        file = open(file_name, 'r')
        data = file.readline()
        return data

    def is_Date(self, date):
        try:
            datetime.datetime.strptime(date, '%d-%m-%Y')
        except ValueError:
            raise ValueError("Incorrect data, should be DD-MM-YY")

    def take_input_from_user(self, main_data):
        data = []
        print('Enter the name')
        while True:
            name = input()
            flag = False
            if (Object_Oriented_Problems.util.is_string(name)):
                for item in main_data:
                    if item[0] == name:
                        flag = True
                        print("Name already present try again")
                if not flag:
                    break
        data.append(name)
        print('Enter the date ob birth')
        while True:
            date_obj = input()
            if (Object_Oriented_Problems.util.is_Date(date_obj)):
                break
        data.append(str(date_obj))
        print('Is date secret?\nif yes enter yes else no')
        while True:
            status = input().lower()
            if status == 'yes':
                break
            if status =='no':
                break
            else:
                print('please enter yes or no')

        data.append(status)
        print("Successfully entered data")
        return data

    def execute(self):
        data = []
        try:
            file = open('objectoriented.txt', 'w')
        except Exception as e:
            print("could not open file")
        try:
            while True:
                print('Enter 1 to enter data\n2 to check in data\n3to exit')
                option = Object_Oriented_Problems.util.get_positive_integer()
                if option == 3:
                    try:
                        file.write(str(data))
                        # pickle.dump(data, 'objectoriented.txt')
                        print("written data successfully")
                    except Exception as e:
                        print("Could no write data as ",e)
                    exit()
                if option == 1:
                    data.append(self.take_input_from_user(data))
                elif option == 2:
                    if len(data) == 0:
                        print("There is no data to search")
                    else:
                        flag = False
                        print("Enter the name to search")
                        while True:
                            name = input()
                            if Object_Oriented_Problems.util.is_string(name):
                                break
                        for item in data:
                            if item[0] == name:
                                flag = True
                                print('data found')
                                if item[2]=='no':
                                    print('Date of birth :', item[1])
                                else:
                                    print("date of birth is secret")
                        if not flag:
                            print('data not found')
        except Exception as e:
            print("The process stopped as ", e)
from Utility.UtilityDataStructures import UtilityDataStructures
util = UtilityDataStructures()
flag: bool = True
while flag:

    try:
        string1 = (input("Enter the string"))

        print("string in lower case ", string1.lower())
        print("string in upper case ", string1.upper())
    except Exception as e:
        print("Process stopped because %s" % e)
    print("To exit press 0 else press any other number")
    if input() == 0:
        flag = False
Example #10
0
from Utility.UtilityDataStructures import UtilityDataStructures
util = UtilityDataStructures()
flag: bool = True
while flag:

    try:
        list1 = [
            'Prayas', 'Deepak', 'Sunil', 'Veejay', 'Suhas', 'Narayan', 'Ajay'
        ]
        list2 = ['Rakesh', 'sunil', 'Manoj']
        print(list1)
        print(list2)
        # call the function and it the value returned is true prints common else says no common element
        if util.if_common_element(list1, list2):
            print("the list have common element")
        else:
            print("no common element")

    except Exception as exep:
        print("Process stopped because %s" % exep)
    print("To exit press 0 else press any other number")
    if input() == 0:
        flag = False
 def __init__(self):
     self.name = list()
     self.dob = list()
     self.util = UtilityDataStructures()
Example #12
0
from Utility.UtilityDataStructures import UtilityDataStructures
import array as array_object
flag: bool = True
while flag:
    try:
        print('Enter the number of elements to be added to the array')
        # object of utility class
        util = UtilityDataStructures()
        # input from user
        num = util.get_positive_integer()
        # empty array
        array = array_object.array('i', [])
        print("Enter the elements for the array")
        # counts number of times the number occured
        count = 0
        counter = 0
        # storing input from user
        while counter in range(0, num):
            numinput = util.get_integer()
            array.append(numinput)
            counter += 1

        print("Enter the number to be searched")
        # getting number to be searched
        search = util.get_integer()
        counter = 0
        for counter in range(0, num):
            if array[counter].__eq__(search):
                count += 1
        print("The number of occurrences  of ", search, " are ", count)
    except Exception as e:
Example #13
0
from Utility.UtilityDataStructures import UtilityDataStructures
util = UtilityDataStructures()
flag: bool = True
while flag:

    try:
        list1 = [
            'Prayas', 'Deepak', 'Sunil', 'Veejay', 'Suhas', 'Narayan', 'Ajay'
        ]
        print("Enter the length ")
        length = util.get_positive_integer()
        # iterating through the list
        for string in list1:
            # printing only those whose length is more than length specified by user
            if string.__len__() > length:
                print(string)

    except Exception as exep:
        print("Process stopped because %s" % exep)
    print("To exit press 0 else press any other number")
    if input() == 0:
        flag = False
Example #14
0
from Utility.UtilityDataStructures import UtilityDataStructures
util = UtilityDataStructures()
flag: bool = True
while flag:
    try:
        dict1 = {"0": 11, "1": 13, "2": 12, "3": 16, '4': 14}
        print("The dictionary before sorting is")
        # printing the dictionary
        for key in dict1:
            print("For key ", key, " value is: ", dict1[key])
        # taking user input
        print("Enter the key to be added")
        inputkey = util.get_integer()
        print("Enter the value to be added")
        inputvalue = util.get_integer()

        print("the dict after manipulation with key")
        # adding the input to the dictionary
        dict1[inputkey.__str__()] = inputvalue
        print(dict1)
    except Exception as e:
        print("Process stopped because %s" % e)
    print("To exit press 0 else press any other number")
    if input() == 0:
        flag = False