Introduction. Have you ever wondered how to build a scalable system like the one you use most for interview practice? Leetcode has become a cornerstone for s...
Gmail, one of the most popular email services in the world, supports millions of users, delivering robust performance, high availability, and strong security...
Introduction:. In today's mobile-first world, having a website that performs seamlessly on mobile devices is no longer optional—it's imperative. Mobile optim...
Create the Lazy-Loaded Component. In the application, add a new component using the Angular CLI command, as shown below.
Basic Introduction. Nodejs is a JavaScript runtime build over Chrome's V8 JavaScript engine. Nodejs is generally used a backend tool to cater to client apis.
At times we must have come across a situation wherein we had to scrap a website and process the data in some way, like. ,
def reverseWord(word): output = "" for w in word: output = w + output return output def reverseWord2(word): start = 0 end = word.length while (start < end): def reverseSentence(sentence): words = sentence.split(" ") output = "" for word in words: output = reverseWord(word) + " " + output return output print(reverseWord("Tipalti")) input2 = "Tipalti is an AP automation leader" print(reverseSentence(input2))
Abom = [range(6, 12), range(7, 14), range(8, 16), range(10, 19), range(11, 21)] Anti = [range(3, 6), range(4, 7), range(4, 8), range(5, 9), range(5, 10)] Arb = [range(4, 9), range(5, 11), range(6, 12), range(6, 14), range(7, 15)] BH = [range(5, 11), range(6, 13), range(7, 14), range(7, 16), range(8, 17)] Cru = [range(6, 13), range(7, 15), range(8, 17), range(9, 18), range(10, 20)] Flag = [range(3, 7), range(4, 8), range(4, 9), range(5, 11), range(5, 12)] HWM = [range(5, 11), range(6, 13), range(7, 14), range(8, 16), range(9, 17)] HM = [range(4, 8), range(5, 9), range(6, 11), range(6, 12), range(7, 14)] Lep = [range(8, 17), range(9, 19), range(10, 22), range(12, 24), range(13, 27)] MaA = [range(5, 10), range(6, 11), range(7, 13), range(7, 14), range(8, 15)] SB = [range(5, 11), range(6, 13), range(7, 15), range(8, 17), range(9, 19)] import math hero = input("Please enter the hero of interest [Abom, Anti, Arb, BH, Cru, Flag, GR, Helli, HWM, HM, Jest, Lep, MaA, Musk, Occ, PD, SB, Vest] or q to quit:\n") while hero != "q": weapon_lvl = int(input("Please enter the weapon level of interest [1, 2, 3, 4, 5]:\n")) crit = float(input("Please enter a crit value between 0 and 1:\n")) damage_mod = float(input("Please enter the final damage modifier according to the following formula: (ability mod) * (sum of trinkets, quirks, buffs):\n")) multiplier = 1 + damage_mod if hero == "Abom": index = Abom elif hero == "Anti": index = Anti elif hero == "Arb" or hero == "GR" or hero =="Musk" or hero == "Vest": index = Arb elif hero == "BH": index = BH elif hero == "Cru" or hero == "Helli": index = Cru elif hero == "Flag": index = Flag elif hero == "HWM": index = HWM elif hero == "HM" or hero == "Jest" or hero == "Occ" or hero == "PD": index = HM elif hero == "Lep": index = Lep elif hero == "MaA": index = MaA elif hero == "SB": index = SB damage = index[weapon_lvl-1] expected_damage = round(damage[-1] * multiplier * 1.5) * crit for i in damage: expected_damage = expected_damage + (math.ceil(i*multiplier) * ((1-crit)/len(damage))) print("When it comes to a(n)", hero, "with level", weapon_lvl, "weapons:") print("The expected damage given", str(crit * 100) + "%", "crit and a", multiplier, "damage multiplier is {:.2f}.".format(expected_damage)) print() hero = input("Please enter the hero of interest [Abom, Anti, Arb, BH, Cru, Flag, GR, Helli, HWM, HM, Jest, Lep, MaA, Musk, Occ, PD, SB, Vest] or q to quit:\n")
def knapsack_with_mandatory(capacity, file_sizes, mandatory_index): n = len(file_sizes) mandatory_size = file_sizes[mandatory_index] # Convert all sizes to integers (bytes) to avoid floating point issues capacity = int(capacity * 1000) # Convert MB to KB file_sizes = [int(size * 1000) for size in file_sizes] # Convert MB to KB mandatory_size = file_sizes[mandatory_index] # Reduce capacity by the size of the mandatory file remaining_capacity = capacity - mandatory_size # Create a new list without the mandatory file remaining_files = file_sizes[:mandatory_index] + file_sizes[mandatory_index+1:] dp = [[0 for _ in range(remaining_capacity + 1)] for _ in range(n)] for i in range(1, n): for w in range(1, remaining_capacity + 1): if remaining_files[i-1] <= w: dp[i][w] = max(remaining_files[i-1] + dp[i-1][w-remaining_files[i-1]], dp[i-1][w]) else: dp[i][w] = dp[i-1][w] # Backtrack to find which files were included w = remaining_capacity included_files = [mandatory_index] # Start with the mandatory file for i in range(n-1, 0, -1): if dp[i][w] != dp[i-1][w]: if i >= mandatory_index: included_files.append(i+1) else: included_files.append(i) w -= remaining_files[i-1] return (dp[n-1][remaining_capacity] + mandatory_size) / 1000, included_files[::-1] # Convert KB back to MB # File sizes in MB file_sizes = [33.7, 16.2, 1.5, 1.0, 1.8, 2.7, .9, 6.6, 5.2, 2.0, 1.8, 1.1, 5.1, 6.4, 7.3] capacity = 20 # Hard drive capacity in MB mandatory_file = 14 # Index of file 15 (remember, Python uses 0-based indexing) total_size, selected_files = knapsack_with_mandatory(capacity, file_sizes, mandatory_file) print(f"Maximum total size: {total_size:.1f} MB") print("Selected files:") for i in selected_files: print(f"File {i+1}: {file_sizes[i]} MB") print(f"Total size of selected files: {sum([file_sizes[i] for i in selected_files]):.1f} MB") print(f"Unused space: {capacity - sum([file_sizes[i] for i in selected_files]):.1f} MB")
# Function definition starts with no indentation def greet(name): # Inside the function, the code block is indented if name: # Inside the if statement, another level of indentation print(f"Hello, {name}!") else: # Same level of indentation as the previous if block print("Hello, world!") # Call the function greet("Alice")
def listsum(a,b): print("Sum: ",(a+b)) listsum(10,20)