Employee Salary Slip and Program Tasks
Employee Salary Slip and Program Tasks
Split the string into words, capitalize the first letter of each word using a method like .capitalize() or .title(), and check each word’s length. Reverse words containing exactly three letters by slicing with a step of -1. Join these processed words back into a single string .
Traverse each character in the input string, checking for digits using character properties like .isdigit(). Accumulate digits into a temporary string, converting this string to an integer once a non-digit character is encountered, and add it to a running total. Handle missing digits by defaulting to zero sum .
To find palindrome words in a string, split the sentence into individual words and check each word by reversing it and comparing it to the original. If the reversed word matches the original, it is a palindrome. Print or store any words that satisfy this condition .
To reverse a number and count the odd and even digits, use a while loop to iterate through each digit of the number, appending it to a new reversed number variable. During each iteration, check if the digit is odd or even by using modulus operation (digit % 2) and increment the respective counter. Continue this process until no digits remain in the original number .
To swap elements at even and odd locations in a list, iterate over the list indices using a step size of 2. For each even index, swap the element with the subsequent odd index using a temporary variable or tuple swapping. Continue until the end of the list .
Parse through a composite list holding student details either as a dictionary or nested list, extracting relevant indices for each student’s name and scores. Calculate and store totals and averages, then display each student’s data neatly, leveraging string formatting for alignment .
To calculate the net pay of an employee, start by identifying the following components: DA (Dearness Allowance), which is 20% of Basic Pay (BP); HRA (House Rent Allowance), which is 30% of BP; TA (Travel Allowance), which is 10% of BP; PF (Provident Fund), which is 13% of BP; and IT (Income Tax), which is 5% of BP. Compute the Gross Pay as BP + DA + HRA + TA. Then calculate the total deductions as PF + IT. Finally, determine the net pay by subtracting the total deductions from the gross pay .
Identify the indices of the start substring (S2) and end substring (S3) in the given string (S1). Extract the portion to replace by finding the position immediately after S2 and stopping just before S3 ends. Replace this range with a new substring (S4) by concatenating the parts of S1 before S2, S4, and the remaining S1 following S3 .
To find the LCM and GCD of two numbers programmatically, the Euclidean algorithm efficiently finds the GCD by repeatedly applying the operation gcd(a, b) = gcd(b, a % b) until b equals zero. The LCM can then be derived from the relation LCM(a, b) = (a * b) / GCD(a, b).
Iterate through the list, maintaining a set to track seen elements. For each element, check if it's not in the set, append it back to the same list, marking it as seen. Finally, trim the list to contain only the added unique elements .