def add_new_person(self): print('Enter Your Name') name = self.utility_obj.get_string() print('Enter Your Email Id') emailid = self.utility_obj.get_string() print('Enter Your Address') address = self.utility_obj.get_string() print('Enter Your Contact Number') number = self.utility_obj.get_int() print("Enter Number of share if yoy have any ,else enter zero") share_no = balance = Utility().get_int() print('Enter Your Total Balance') balance = Utility().get_int() new_person_dict = { "Name": name, "Email id": emailid, "Address": address, "Contact": number, "Number of Share": share_no, "Total Balance": balance } with open('../util/Person.json', 'w') as person_jf: person_json_value['Person'].append(new_person_dict) person_jf.write(json.dumps(person_json_value)) person_jf.close()
def __init__(self, json_value, name=json_value["Rice"][0]["name"], weight=json_value["Rice"][0]["weight"], price_per_kg=json_value["Rice"][0]["price per kg"]): self.existing_material = json_value self.json_value = json_value self.name = name self.weight = weight self.price_per_kg = price_per_kg self.utility_obj = Utility() # print("\033[1;32;40m Bright Green \n") print( "\n<--- Just Look at the Materials that We have in our Inventory and Select Accordingly --->\n" )
def runCoupon(): """Connects to the next_node available port. Args: Raises: ValueError: If the minimum port specified is less than 1024. ConnectionError: If no available port is found. Returns: The new minimum port. """ try: utility_obj = Utility() print("Enter Number of Coupans you want") no_of_coupans = utility_obj.get_int() random_number_count, store_coupans = utility_obj.coupan_generator( no_of_coupans) print( "Number of Random Number Needed to Generate given number of coupans =>" + str(random_number_count)) print("The Distinct Coupans are as follows") for i in store_coupans: print(i) except: print("error")
def regex(self): string = ' Hello <<name>>, We have your full name as <<full name>> in our system.\n your contact number is 91-xxxxxxxxxx.\n Please,let us know in case of any clarification Thank you BridgeLabz 01/01/2016. ' template = ['<<name>>', '<<full name>>', 'xxxxxxxxxx', '01/01/2016'] list = [ 'Enter Your First Name', 'Enter Your Full Name', 'Enter Your Mobile Number', "Enter Today's Date" ] for i in range(4): print(' =>', list[i]) replaced_string = re.sub(template[i], Utility().get_string(), string, 1) string = replaced_string return string
def add_new_company(self): print('Enter Stock Name or company Name') name = self.utility_obj.get_string() print('Enter Your Number of share') number = self.utility_obj.get_int() print('Enter Your Price per share') price = Utility().get_int() new_stock_dict = { "Stock Name": name, "Number of Share": number, "Share Price": price } with open('../util/Stock Report.json', 'w') as stock_jf: self.stock_jf['Stock Report'].append(new_stock_dict) stock_jf.write(json.dumps(self.stock_jf)) stock_jf.close()
from com.bridgelabz.util.utility import Utility utility_obj=Utility() store_prime_palindrome=utility_obj.get_palindrome_prime() print("The Prime Numbers which are Palindrome are as follows") for i in store_prime_palindrome: print(i) print("The Preme Numbers which are Anagram are as follows") utility_obj.get_anagram_prime()
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter First string") first_string = utility_obj.get_string() print("Enter Second string") second_string = utility_obj.get_string() utility_obj.anagram_detection(first_string, second_string)
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("enter string to see all permutation of it ") string = utility_obj.get_string() n = len(string) a = list(string) utility_obj.permute(a, 0, n - 1)
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter Number to get its squareroot ") NUMBER = utility_obj.get_int() SQUARE_ROOT = Utility.newtons_sqrt_method(NUMBER) print("Square Root of Your Number " + str(NUMBER) + " is " + str(SQUARE_ROOT))
from com.bridgelabz.util.utility import Utility utility_obj = Utility() list = utility_obj.get_prime_factors() for i in list: print(i)
""" This program actually gives the number of notes and which note is required for a particular amount. """ from __future__ import print_function from com.bridgelabz.util.utility import Utility print("Enter Money") MONEY_AMOUNT = Utility().get_int() VENDING_RESULT = Utility.get_vending_machine_result(MONEY_AMOUNT) for i in VENDING_RESULT: print(i + " " + str(VENDING_RESULT.get(i, -1)))
def replacing(self): i = 0 while i < len(self.list_cards): if bool(re.search('Ace', self.list_cards[i])): self.list_cards[i] = re.sub('Ace', '14', self.list_cards[i], 1) if bool(re.search('Jack', self.list_cards[i])): self.list_cards[i] = re.sub('Jack', '11', self.list_cards[i], 1) if bool(re.search('Queen', self.list_cards[i])): self.list_cards[i] = re.sub('Queen', '12', self.list_cards[i], 1) if bool(re.search('King', self.list_cards[i])): self.list_cards[i] = re.sub('King', '13', self.list_cards[i], 1) i += 1 ranks = [] number = [] i = 0 while i < len(self.list_cards): ranks.append(self.list_cards[i].split(" ")) number.append(int(ranks[i][0])) i += 1 number = Utility().bubblesort_for_integer(number) i = 0 sorted_card = [] suits = ["Clubs", "Diamonds", "Hearts", "Spades"] while i < 36: string = '' random_no = random.randint(0, 3) string = suits[random_no] string = str(number[i]) + " " + string while sorted_card.__contains__(string) is True: random_no = random.randint(0, 3) string = suits[random_no] string = str(number[i]) + ' ' + string if sorted_card.__contains__(string) is False: sorted_card.append(string) i += 1 i = 0 while i < len(sorted_card): if bool(re.search('14', sorted_card[i])): sorted_card[i] = re.sub('14', 'Ace', sorted_card[i], 1) if bool(re.search('11', sorted_card[i])): sorted_card[i] = re.sub('11', 'Jack', sorted_card[i], 1) if bool(re.search('12', sorted_card[i])): sorted_card[i] = re.sub('12', 'Queen', sorted_card[i], 1) if bool(re.search('13', sorted_card[i])): sorted_card[i] = re.sub('13', 'King', sorted_card[i], 1) i += 1 player_objs = [] limit = 0 index = 9 for i in range(0, 4): player_objs.append(Player(card.shuffle(), Utility(), Queue())) for sorted_cards in sorted_card: if limit < index: player_objs[i].queue.enqueue(sorted_card[limit]) limit += 1 index += 9 for i in range(0, 4): print('Player', i + 1, '\n', '----------') print(player_objs[i].queue.show()) print('\n')
class Inventory: with open('../util/Inventory.json', 'r') as jf: json_str = jf.read() jf.close() json_value = json.loads(json_str) def __init__(self, json_value, name=json_value["Rice"][0]["name"], weight=json_value["Rice"][0]["weight"], price_per_kg=json_value["Rice"][0]["price per kg"]): self.existing_material = json_value self.json_value = json_value self.name = name self.weight = weight self.price_per_kg = price_per_kg self.utility_obj = Utility() # print("\033[1;32;40m Bright Green \n") print( "\n<--- Just Look at the Materials that We have in our Inventory and Select Accordingly --->\n" ) list_keys = [] key_index = 0 material_chosen = '' def inventory_materials(self): json_keys = self.json_value.keys() for key in json_keys: self.list_keys.append(key) for i in self.list_keys: print(self.key_index, i) self.key_index += 1 self.key_index = self.utility_obj.get_int() self.material_chosen = self.list_keys[self.key_index] def see_category(self): index = 0 for i in self.json_value: if i == self.material_chosen: print("Now Look at the Category for ->", self.material_chosen, "<- that We have in our Inventory\n") for j in self.json_value[self.material_chosen]: print(index, j) index += 1 index_update = index print( index_update, "If you did not find your match in our listed Category of ", self.material_chosen, '\n Then Just add your required category of', self.material_chosen, '\n You can get it by Tomorrow\n') choice = self.utility_obj.get_int() if index_update == choice: self.update_category() return else: price_per_kg = self.json_value[ self.material_chosen][choice]["price per kg"] self.set_price_per_kg(price_per_kg) print('Enter how many kilograms you want to buy') weight = self.utility_obj.get_int() self.set_weight(weight) print('your total price is ') print(self.get_price()) def update_category(self): print("Enter Your Requirement Now\n") user_requirement = self.utility_obj.get_string() with open('../util/Inventory.json', 'r') as jf: json_str = jf.read() jf.close() json_value = json.loads(json_str) with open('../util/Inventory.json', 'w') as jf: json_value[self.material_chosen].append({ "name": user_requirement, "weight": 1, "price per kg": 50 }) jf.write(json.dumps(json_value)) jf.close() def get_name(self): return self.name def set_name(self, value): self.name = value def get_weight(self): return self.weight def set_weight(self, weight): self.weight = weight def get_price_per_kg(self): return self.price_per_kg def set_price_per_kg(self, price_per_kg): self.price_per_kg = price_per_kg def get_price(self): price = self.get_price_per_kg() * self.get_weight() return price
" Mobile Number": "Dermatologist", " Availability": "AM" }] } Patients_dict = { "Patients": [{ "Name": "Rohini Zade", "Id": 1, "Mobile Number": 9967493198, " Age": 23 }, { "Name": "Reshma Kale", "Id": 2, "Mobile Number": 9967493197, " Age": 22 }] } with open('../util/Person.json', 'w') as person_jf: person_jf.write(json.dumps(P)) person_jf.close() class Clinique: def __init__(self, utility_obj): self.utility_obj = utility_obj clinique = Clinique(Utility())
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter Stake") stake = utility_obj.get_int() print("Enter goal") goal = utility_obj.get_int() print("Enter number of times you want to play") no_of_times = utility_obj.get_int() win_count, win_percent, lose_percent = utility_obj.get_gambling_result( stake, goal, no_of_times) print(win_count) print(win_percent) print(lose_percent)
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("1.convert Celsius to Fahrenheit ") print("2.convert Fahrenheit to Celsius ") CHOICE = utility_obj.get_int() TEMPERATURE = Utility.temperature_conversion(CHOICE) print(TEMPERATURE)
from com.bridgelabz.util.utility import Utility from timeit import default_timer import time #from time import clock_gettime_ns utility_obj = Utility() execution_time = {} execution_time["Method Name"] = "Execution Time" print( "1.Binary Search for Integer\n2.Binary_search_for_string\n3.insertionsort_for_integer\n4.Insertion sort for string\n5.bubblesort_for_integer\n6.bubblesort_for_string" ) choice = utility_obj.get_int() ##########################################################Binary Search for Integer#################################### if (choice == 1): print("Enter number of elements you want to put in list") list_int_size = utility_obj.get_int() print("Now enter all elements") store_user_value = [] for i in range(0, list_int_size): store_user_value.append(utility_obj.get_int()) print("Enter which element you are looking for") search_item = utility_obj.get_int() #start_time=default_timer() start_time = (time.time() * 1000 * 1000) search_item_index = Utility.binary_search_for_int(store_user_value, search_item) #end_time=default_timer()
from com.bridgelabz.util.utility import Utility utility_obj = Utility() sorted_int_list = Utility.bubblesort_file() for i in sorted_int_list: print(i, end=" ")
from com.bridgelabz.util.utility import Utility utility_obj=Utility() list=Utility.binarysearch_wordlist() print("These are the list of items we have in our list\n") for i in list: print(i,end=" ") print("\n\nEnter word you are looking for") search_item=Utility().get_string() search_item_index=Utility.binary_search_for_string(list,search_item) if search_item_index != -1: print(str(list[search_item_index]) + " index => " + str(search_item_index))
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter the size of list") list_size = utility_obj.get_int() print("Enter values") user_list = [] for i in range(0, list_size): user_list.append(utility_obj.get_int()) sorted_values = utility_obj.mergesort(user_list) for i in sorted_values: print(i, end=" ")
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter principle") PRINCIPLE=utility_obj.get_int() print("Enter Rate") RATE=utility_obj.get_int() print("Enter Year") YEAR=utility_obj.get_int() Utility.monthly_payment(PRINCIPLE,RATE,YEAR)
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter Year") Year = utility_obj.get_string() print(utility_obj.isleap_year(Year))
from com.bridgelabz.util.utility import Utility sorted_list = Utility.appendionsort_file() for i in sorted_list: print(i, end=" ")
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Use StopWatch => 1:Start\n" + " 2:Stop") choice = utility_obj.get_int() utility_obj.get_elapsed_time(choice)
from com.bridgelabz.util.utility import Utility import sys utility_obj = Utility() x_coordinate = int(sys.argv[1]) y_coordinate = int(sys.argv[2]) # print("Enter x_coordinate ") # x_coordinate =utility_obj.get_int() # print(" Enter y_coordinate ") # y_coordinate =utility_obj.get_int() euclidean_distance = utility_obj.get_euclidean_distance( x_coordinate, y_coordinate) print(euclidean_distance)
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter decimal value") decimal_value = utility_obj.get_int() decimal_value = Utility.todecimal_of_swap_nibble(decimal_value) print(decimal_value)
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter decimal number to convert into binary representation") DECIMAL_VALUE = utility_obj.get_int() BINARY_REPRESENTATION = Utility.to_binary(DECIMAL_VALUE) print( str(DECIMAL_VALUE) + " -> binary representation -> " + str(BINARY_REPRESENTATION))
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter Number of Times You want to flip coin") times = utility_obj.get_int() head, tail = utility_obj.get_probability(times) print("Head Percentage " + str(head)) print("Tail Percentage " + str(tail))
from com.bridgelabz.util.utility import Utility utility_obj = Utility() utility_obj = Utility() store_prime = utility_obj.get_prime() for i in store_prime: print(i)
from com.bridgelabz.util.utility import Utility utility_obj = Utility() print("Enter Number of values you want to enter") no_of_values = utility_obj.get_int() print("Enter values now") store_values = [] for i in range(0, no_of_values): value = utility_obj.get_int() store_values.append(value) utility_obj.find_triplet(store_values)