common_id
stringlengths 5
5
| image
stringlengths 24
24
| code
stringlengths 43
914
|
---|---|---|
11782 | Validation/png/11782.png | def fun100(N, k):
sum = 0
i = 1
while i <= N:
if i % k == 0:
sum = sum + i
i = i + 1
return sum |
11852 | Validation/png/11852.png | def fun170(string):
length = len(string)
count = 0
for i in range(length):
ch = string[i]
if ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u':
count = count + 1
count = length - count
return count |
11490 | Validation/png/11490.png | # Write a python function to find the sum of all odd length subarrays.
def Odd_Length_Sum(arr):
Sum = 0
l = len(arr)
for i in range(l):
Sum += (((i + 1) * (l - i) + 1) // 2) * arr[i]
return Sum
|
11738 | Validation/png/11738.png | def fun56(CP, SP):
if CP > SP:
return CP - SP
else:
return SP - CP |
11315 | Validation/png/11315.png | # Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs by using regex.
import re
pattern = "fox"
text = "The quick brown fox jumps over the lazy dog."
def find_literals(text, pattern):
match = re.search(pattern, text)
s = match.start()
e = match.end()
return (match.re.pattern, s, e)
|
11531 | Validation/png/11531.png | # Write a function to check if the given string starts with a substring using regex.
import re
def check_substring(string, sample):
if sample in string:
y = "\A" + sample
x = re.search(y, string)
if x:
return "string starts with the given substring"
else:
return "string doesnt start with the given substring"
else:
return "entered string isnt a substring"
|
11740 | Validation/png/11740.png | def fun58(num1, num2):
if num1 == num2:
return 'Both are equal'
else:
return 'Both are not equal' |
11501 | Validation/png/11501.png | # Write a python function to find the last position of an element in a sorted array.
def last(arr, x, n):
low = 0
high = n - 1
res = -1
while low <= high:
mid = (low + high) // 2
if arr[mid] > x:
high = mid - 1
elif arr[mid] < x:
low = mid + 1
else:
res = mid
low = mid + 1
return res
|
11330 | Validation/png/11330.png | # Write a function to find the median of two sorted arrays of same size.
def get_median(arr1, arr2, n):
i = 0
j = 0
m1 = -1
m2 = -1
count = 0
while count < n + 1:
count += 1
if i == n:
m1 = m2
m2 = arr2[0]
break
elif j == n:
m1 = m2
m2 = arr1[0]
break
if arr1[i] <= arr2[j]:
m1 = m2
m2 = arr1[i]
i += 1
else:
m1 = m2
m2 = arr2[j]
j += 1
return (m1 + m2) / 2
|
11452 | Validation/png/11452.png | # Write a function to check if the given tuple has any none value or not.
def check_none(test_tup):
res = any(map(lambda ele: ele is None, test_tup))
return res
|
11865 | Validation/png/11865.png | def fun183(a, r, N):
term = a * r ** (N - 1)
return term |
11471 | Validation/png/11471.png | # Write a python function to find the minimum difference between any two elements in a given array.
def find_Min_Diff(arr, n):
arr = sorted(arr)
diff = 10**20
for i in range(n - 1):
if arr[i + 1] - arr[i] < diff:
diff = arr[i + 1] - arr[i]
return diff
|
11606 | Validation/png/11606.png | # Write a function to extract specified number of elements from a given list, which follow each other continuously.
from itertools import groupby
def extract_elements(numbers, n):
result = [i for i, j in groupby(numbers) if len(list(j)) == n]
return result
|
11751 | Validation/png/11751.png | def fun69(string1, string2):
if string1 == string2:
return 'Both are equal'
else:
return 'Both are not equal' |
11372 | Validation/png/11372.png | # Write a python function to find the average of even numbers till a given even number.
def average_Even(n):
if n % 2 != 0:
return "Invalid Input"
return -1
sm = 0
count = 0
while n >= 2:
count = count + 1
sm = sm + n
n = n - 2
return sm // count
|
11394 | Validation/png/11394.png | # Write a function to find the frequency of each element in the given list.
from collections import defaultdict
def freq_element(test_tup):
res = defaultdict(int)
for ele in test_tup:
res[ele] += 1
return str(dict(res))
|
11399 | Validation/png/11399.png | # Write a function to group the 1st elements on the basis of 2nd elements in the given tuple list.
from itertools import groupby
def group_element(test_list):
res = dict()
for key, val in groupby(
sorted(test_list, key=lambda ele: ele[1]), key=lambda ele: ele[1]
):
res[key] = [ele[0] for ele in val]
return res
|
11628 | Validation/png/11628.png | # Write a function to remove all tuples with all none values in the given tuple list.
def remove_tuple(test_list):
res = [sub for sub in test_list if not all(ele == None for ele in sub)]
return str(res)
|
11660 | Validation/png/11660.png | # Write a function to compute the value of ncr mod p.
def nCr_mod_p(n, r, p):
if r > n - r:
r = n - r
C = [0 for i in range(r + 1)]
C[0] = 1
for i in range(1, n + 1):
for j in range(min(i, r), 0, -1):
C[j] = (C[j] + C[j - 1]) % p
return C[r]
|
11333 | Validation/png/11333.png | # Write a python function to interchange first and last elements in a given list.
def swap_List(newList):
size = len(newList)
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
|
11426 | Validation/png/11426.png | # Write a function to create a list taking alternate elements from another given list.
def alternate_elements(list1):
result = []
for item in list1[::2]:
result.append(item)
return result
|
11540 | Validation/png/11540.png | # Write a function to extract the maximum numeric value from a string by using regex.
import re
def extract_max(input):
numbers = re.findall("\d+", input)
numbers = map(int, numbers)
return max(numbers)
|
11314 | Validation/png/11314.png | # Write a function to convert degrees to radians.
import math
def radian_degree(degree):
radian = degree * (math.pi / 180)
return radian
|
11560 | Validation/png/11560.png | # Write a python function to remove negative numbers from a list.
def remove_negs(num_list):
for item in num_list:
if item < 0:
num_list.remove(item)
return num_list
|
11410 | Validation/png/11410.png | # Write a function to find the minimum number of elements that should be removed such that amax-amin<=k.
def find_ind(key, i, n, k, arr):
ind = -1
start = i + 1
end = n - 1
while start < end:
mid = int(start + (end - start) / 2)
if arr[mid] - key <= k:
ind = mid
start = mid + 1
else:
end = mid
return ind
def removals(arr, n, k):
ans = n - 1
arr.sort()
for i in range(0, n):
j = find_ind(arr[i], i, n, k, arr)
if j != -1:
ans = min(ans, n - (j - i + 1))
return ans
|
11456 | Validation/png/11456.png | # Write a function to put spaces between words starting with capital letters in a given string by using regex.
import re
def capital_words_spaces(str1):
return re.sub(r"(\w)([A-Z])", r"\1 \2", str1)
|
11603 | Validation/png/11603.png | # Write a function to find the maximum sum of subsequences of given array with no adjacent elements.
def max_sum_subseq(A):
n = len(A)
if n == 1:
return A[0]
look_up = [None] * n
look_up[0] = A[0]
look_up[1] = max(A[0], A[1])
for i in range(2, n):
look_up[i] = max(look_up[i - 1], look_up[i - 2] + A[i])
look_up[i] = max(look_up[i], A[i])
return look_up[n - 1]
|
11579 | Validation/png/11579.png | # Write a python function to check whether the given strings are rotations of each other or not.
def are_Rotations(string1, string2):
size1 = len(string1)
size2 = len(string2)
temp = ""
if size1 != size2:
return False
temp = string1 + string1
if temp.count(string2) > 0:
return True
else:
return False
|
11710 | Validation/png/11710.png | def fun28(seconds):
hours = seconds / 3600
return hours |
11418 | Validation/png/11418.png | # Write a function to access the initial and last data of the given tuple record.
def front_and_rear(test_tup):
res = (test_tup[0], test_tup[-1])
return res
|
11561 | Validation/png/11561.png | # Write a python function to find sum of odd factors of a number.
import math
def sum_of_odd_Factors(n):
res = 1
while n % 2 == 0:
n = n // 2
for i in range(3, int(math.sqrt(n) + 1)):
count = 0
curr_sum = 1
curr_term = 1
while n % i == 0:
count += 1
n = n // i
curr_term *= i
curr_sum += curr_term
res *= curr_sum
if n >= 2:
res *= 1 + n
return res
|
11346 | Validation/png/11346.png | # Write a function to calculate wind chill index.
import math
def wind_chill(v, t):
windchill = (
13.12 + 0.6215 * t - 11.37 * math.pow(v, 0.16) + 0.3965 * t * math.pow(v, 0.16)
)
return int(round(windchill, 0))
|
11395 | Validation/png/11395.png | # Write a function to find the greatest common divisor (gcd) of two integers by using recursion.
def recur_gcd(a, b):
low = min(a, b)
high = max(a, b)
if low == 0:
return high
elif low == 1:
return 1
else:
return recur_gcd(low, high % low)
|
11358 | Validation/png/11358.png | # Write a python function to check whether the given two arrays are equal or not.
def are_Equal(arr1, arr2, n, m):
if n != m:
return False
arr1.sort()
arr2.sort()
for i in range(0, n - 1):
if arr1[i] != arr2[i]:
return False
return True
|
11391 | Validation/png/11391.png | # Write a python function to check whether the given number can be represented by sum of two squares or not.
def sum_Square(n):
i = 1
while i * i <= n:
j = 1
while j * j <= n:
if i * i + j * j == n:
return True
j = j + 1
i = i + 1
return False
|
11609 | Validation/png/11609.png | # Write a function to find the smallest multiple of the first n numbers.
def smallest_multiple(n):
if n <= 2:
return n
i = n * 2
factors = [number for number in range(n, 1, -1) if number * 2 > n]
while True:
for a in factors:
if i % a != 0:
i += n
break
if a == factors[-1] and i % a == 0:
return i
|
11429 | Validation/png/11429.png | # Write a function to find a path with the maximum average over all existing paths for the given square matrix of size n*n.
M = 100
def maxAverageOfPath(cost, N):
dp = [[0 for i in range(N + 1)] for j in range(N + 1)]
dp[0][0] = cost[0][0]
for i in range(1, N):
dp[i][0] = dp[i - 1][0] + cost[i][0]
for j in range(1, N):
dp[0][j] = dp[0][j - 1] + cost[0][j]
for i in range(1, N):
for j in range(1, N):
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + cost[i][j]
return dp[N - 1][N - 1] / (2 * N - 1)
|
11377 | Validation/png/11377.png | # Write a function to check whether the given ip address is valid or not using regex.
import re
regex = """^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.(
25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$"""
def check_IP(Ip):
if re.search(regex, Ip):
return "Valid IP address"
else:
return "Invalid IP address"
|
11415 | Validation/png/11415.png | # Write a python function to count the total set bits from 1 to n.
def count_Set_Bits(n):
n += 1
powerOf2 = 2
cnt = n // 2
while powerOf2 <= n:
totalPairs = n // powerOf2
cnt += (totalPairs // 2) * powerOf2
if totalPairs & 1:
cnt += n % powerOf2
else:
cnt += 0
powerOf2 <<= 1
return cnt
|
11850 | Validation/png/11850.png | def fun168(string):
length = len(string)
count = 0
for i in range(length):
ch = string[i]
if ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u':
count = count + 1
return count
|
11487 | Validation/png/11487.png | # Write a function to count the number of unique lists within a list.
def unique_sublists(list1):
result = {}
for l in list1:
result.setdefault(tuple(l), list()).append(1)
for a, b in result.items():
result[a] = sum(b)
return result
|
11725 | Validation/png/11725.png | def fun43(x, y):
if x < y:
mn = x
else:
mn = y
return mn |
11525 | Validation/png/11525.png | # Write a function to find numbers divisible by m or n from a list of numbers using lambda function.
def div_of_nums(nums, m, n):
result = list(filter(lambda x: (x % m == 0 or x % n == 0), nums))
return result
|
11486 | Validation/png/11486.png | # Write a function to pack consecutive duplicates of a given list elements into sublists.
from itertools import groupby
def pack_consecutive_duplicates(list1):
return [list(group) for key, group in groupby(list1)]
|
11653 | Validation/png/11653.png | # Write a function to convert the given tuples into set.
def tuple_to_set(t):
s = set(t)
return s
|
11323 | Validation/png/11323.png | # Write a function to find average value of the numbers in a given tuple of tuples.
def average_tuple(nums):
result = [sum(x) / len(x) for x in zip(*nums)]
return result
|
11803 | Validation/png/11803.png | def fun121(a, r, N):
term = a
for i in range(1, N):
term = term * r
return term
|
11607 | Validation/png/11607.png | # Write a python function to check whether an array can be sorted or not by picking only the corner elements.
def check(arr, n):
g = 0
for i in range(1, n):
if arr[i] - arr[i - 1] > 0 and g == 1:
return False
if arr[i] - arr[i] < 0:
g = 1
return True
|
11416 | Validation/png/11416.png | # Write a python function to convert a string to a list.
def Convert(string):
li = list(string.split(" "))
return li
|
11551 | Validation/png/11551.png | # Write a function to find the nth super ugly number from a given prime list of size k using heap queue algorithm.
import heapq
def nth_super_ugly_number(n, primes):
uglies = [1]
def gen(prime):
for ugly in uglies:
yield ugly * prime
merged = heapq.merge(*map(gen, primes))
while len(uglies) < n:
ugly = next(merged)
if ugly != uglies[-1]:
uglies.append(ugly)
return uglies[-1]
|
11776 | Validation/png/11776.png | def fun94(a, b):
sum = 0
i = a
while i <= b:
if i % 2 == 0:
sum = sum + i
i = i + 1
return sum |
11371 | Validation/png/11371.png | # Write a function to find the largest possible value of k such that k modulo x is y.
import sys
def find_max_val(n, x, y):
ans = -sys.maxsize
for k in range(n + 1):
if k % x == y:
ans = max(ans, k)
return ans if (ans >= 0 and ans <= n) else -1
|
11771 | Validation/png/11771.png | def fun89(num):
res = 0
order = 1
while num != 0:
rem = num % 2
res = rem * order + res
num = num // 2
order = order * 10
return res |
11496 | Validation/png/11496.png | # Write a function to create a new tuple from the given string and list.
def new_tuple(test_list, test_str):
res = tuple(test_list + [test_str])
return res
|
11578 | Validation/png/11578.png | # Write a function to calculate the sum of the positive numbers of a given list of numbers using lambda function.
def sum_positivenum(nums):
sum_positivenum = list(filter(lambda nums: nums > 0, nums))
return sum(sum_positivenum)
|
11450 | Validation/png/11450.png | # Write a function to caluclate the area of a tetrahedron.
import math
def area_tetrahedron(side):
area = math.sqrt(3) * (side * side)
return area
|
11382 | Validation/png/11382.png | # Write a function to remove duplicate words from a given string using collections module.
from collections import OrderedDict
def remove_duplicate(string):
result = " ".join(OrderedDict((w, w) for w in string.split()).keys())
return result
|
11325 | Validation/png/11325.png | # Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.
def min_Jumps(a, b, d):
temp = a
a = min(a, b)
b = max(temp, b)
if d >= b:
return (d + b - 1) / b
if d == 0:
return 0
if d == a:
return 1
else:
return 2
|
11604 | Validation/png/11604.png | # Write a function to sort a list in increasing order by the last element in each tuple from a given list of non-empty tuples.
def last(n):
return n[-1]
def sort_list_last(tuples):
return sorted(tuples, key=last)
|
11592 | Validation/png/11592.png | # Write a python function to check whether all the bits are within a given range or not.
def all_Bits_Set_In_The_Given_Range(n, l, r):
num = ((1 << r) - 1) ^ ((1 << (l - 1)) - 1)
new_num = n & num
if num == new_num:
return True
return False
|
11674 | Validation/png/11674.png | # Write a function to remove an empty tuple from a list of tuples.
def remove_empty(tuple1): # L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
tuple1 = [t for t in tuple1 if t]
return tuple1
|
11828 | Validation/png/11828.png | def fun146(num):
count = 0
while num != 0:
digit = num % 10
if digit == 0:
count = count + 1
num = num // 10
if count > 0:
return 'Duck Number'
else:
return 'Not a Duck Number' |
11826 | Validation/png/11826.png | def fun144(num):
nums = num
rev = 0
while num != 0:
d = num % 10
rev = rev * 10 + d
num = num // 10
if rev == num:
return 'Palindrome Number'
else:
return 'Not a Palindrome Number' |
11600 | Validation/png/11600.png | # Write a function to remove multiple spaces in a string.
import re
def remove_spaces(text):
return re.sub(" +", " ", text)
|
11512 | Validation/png/11512.png | # Write a python function to check whether the product of numbers is even or not.
def is_Product_Even(arr, n):
for i in range(0, n):
if (arr[i] & 1) == 0:
return True
return False
|
11627 | Validation/png/11627.png | # Write a python function to multiply all items in the list.
def multiply_list(items):
tot = 1
for x in items:
tot *= x
return tot
|
11632 | Validation/png/11632.png | # Write a function to find maximum of two numbers.
def max_of_two(x, y):
if x > y:
return x
return y
|
11478 | Validation/png/11478.png | # Write a python function to find the sum of fourth power of first n odd natural numbers.
def odd_Num_Sum(n):
j = 0
sm = 0
for i in range(1, n + 1):
j = 2 * i - 1
sm = sm + (j * j * j * j)
return sm
|
11625 | Validation/png/11625.png | # Write a function to find the sequences of one upper case letter followed by lower case letters.
import re
def text_uppercase_lowercase(text):
patterns = "[A-Z]+[a-z]+$"
if re.search(patterns, text):
return "Found a match!"
else:
return "Not matched!"
|
11437 | Validation/png/11437.png | # Write a function to add two lists using map and lambda function.
def add_list(nums1, nums2):
result = map(lambda x, y: x + y, nums1, nums2)
return list(result)
|
11574 | Validation/png/11574.png | # Write a function to check whether the given month name contains 31 days or not.
def check_monthnumb(monthname2):
if (
monthname2 == "January"
or monthname2 == "March"
or monthname2 == "May"
or monthname2 == "July"
or monthname2 == "Augest"
or monthname2 == "October"
or monthname2 == "December"
):
return True
else:
return False
|
11635 | Validation/png/11635.png | # Write a function to calculate the height of the given binary tree.
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def max_height(node):
if node is None:
return 0
else:
left_height = max_height(node.left)
right_height = max_height(node.right)
if left_height > right_height:
return left_height + 1
else:
return right_height + 1
|
11683 | Validation/png/11683.png | def fun1(x):
y = 16 + x - 20
return y |
11723 | Validation/png/11723.png | def fun41(x, y):
if x > y:
mx = x
else:
mx = y
return mx |
11704 | Validation/png/11704.png | def fun22(x, y):
z = x - y
return z |
11587 | Validation/png/11587.png | # Write a function that matches a string that has an 'a' followed by anything, ending in 'b' by using regex.
import re
def text_match(text):
patterns = "a.*?b$"
if re.search(patterns, text):
return "Found a match!"
else:
return "Not matched!"
|
11610 | Validation/png/11610.png | # Write a function to combine two dictionaries by adding values for common keys.
from collections import Counter
def add_dict(d1, d2):
add_dict = Counter(d1) + Counter(d2)
return add_dict
|
11519 | Validation/png/11519.png | # Write a function to check if two lists of tuples are identical or not.
def check_identical(test_list1, test_list2):
res = test_list1 == test_list2
return res
|
11505 | Validation/png/11505.png | # Write a python function to find the sum of all odd natural numbers within the range l and r.
def sum_Odd(n):
terms = (n + 1) // 2
sum1 = terms * terms
return sum1
def sum_in_Range(l, r):
return sum_Odd(r) - sum_Odd(l - 1)
|
11530 | Validation/png/11530.png | # Write a function to return true if the password is valid.
import re
def pass_validity(p):
x = True
while x:
if len(p) < 6 or len(p) > 12:
break
elif not re.search("[a-z]", p):
break
elif not re.search("[0-9]", p):
break
elif not re.search("[A-Z]", p):
break
elif not re.search("[$#@]", p):
break
elif re.search("\s", p):
break
else:
return True
x = False
break
if x:
return False
|
11347 | Validation/png/11347.png | # Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.
def sample_nam(sample_names):
sample_names = list(
filter(lambda el: el[0].isupper() and el[1:].islower(), sample_names)
)
return len("".join(sample_names))
|
11658 | Validation/png/11658.png | # Write a function to display sign of the chinese zodiac for given year.
def chinese_zodiac(year):
if (year - 2000) % 12 == 0:
sign = "Dragon"
elif (year - 2000) % 12 == 1:
sign = "Snake"
elif (year - 2000) % 12 == 2:
sign = "Horse"
elif (year - 2000) % 12 == 3:
sign = "sheep"
elif (year - 2000) % 12 == 4:
sign = "Monkey"
elif (year - 2000) % 12 == 5:
sign = "Rooster"
elif (year - 2000) % 12 == 6:
sign = "Dog"
elif (year - 2000) % 12 == 7:
sign = "Pig"
elif (year - 2000) % 12 == 8:
sign = "Rat"
elif (year - 2000) % 12 == 9:
sign = "Ox"
elif (year - 2000) % 12 == 10:
sign = "Tiger"
else:
sign = "Hare"
return sign
|
11843 | Validation/png/11843.png | def fun161(string):
length = len(string)
count = 0
i = 0
while i < length:
ascii = ord(string[i])
if ascii >= 97 and ascii <= 122:
count = count + 1
i = i + 1
return count |
11716 | Validation/png/11716.png | def fun34(radian):
degree = radian * 57.2958
return degree |
11872 | Validation/png/11872.png | def fun190(string):
length = len(string)
new = ''
i = length - 1
while i >= 0:
new = new + string[i]
i = i - 1
if string == new:
return 'Palindrome string'
else:
return 'Not a Palindrome string' |
11567 | Validation/png/11567.png | # Write a function to generate all sublists of a given list.
from itertools import combinations
def sub_lists(my_list):
subs = []
for i in range(0, len(my_list) + 1):
temp = [list(x) for x in combinations(my_list, i)]
if len(temp) > 0:
subs.extend(temp)
return subs
|
11476 | Validation/png/11476.png | # Write a python function to check for odd parity of a given number.
def check_Odd_Parity(x):
parity = 0
while x != 0:
x = x & (x - 1)
parity += 1
if parity % 2 == 1:
return True
else:
return False
|
11709 | Validation/png/11709.png | def fun27(hours):
seconds = hours * 3600
return seconds |
11497 | Validation/png/11497.png | # Write a function to calculate the perimeter of a regular polygon.
from math import tan, pi
def perimeter_polygon(s, l):
perimeter = s * l
return perimeter
|
11435 | Validation/png/11435.png | # Write a function to remove all characters except letters and numbers using regex
import re
def remove_char(S):
result = re.sub("[\W_]+", "", S)
return result
|
11667 | Validation/png/11667.png | # Write a python function to find the average of a list.
def Average(lst):
return sum(lst) / len(lst)
|
11409 | Validation/png/11409.png | # Write a function to find the equilibrium index of the given array.
def equilibrium_index(arr):
total_sum = sum(arr)
left_sum = 0
for i, num in enumerate(arr):
total_sum -= num
if left_sum == total_sum:
return i
left_sum += num
return -1
|
11384 | Validation/png/11384.png | # Write a function to remove everything except alphanumeric characters from the given string by using regex.
import re
def remove_extra_char(text1):
pattern = re.compile("[\W_]+")
return pattern.sub("", text1)
|
11613 | Validation/png/11613.png | # Write a python function to find the sum of squares of binomial co-efficients.
def factorial(start, end):
res = 1
for i in range(start, end + 1):
res *= i
return res
def sum_of_square(n):
return int(factorial(n + 1, 2 * n) / factorial(1, n))
|
11582 | Validation/png/11582.png | # Write a python function to check if the string is a concatenation of another string.
def check_Concat(str1, str2):
N = len(str1)
M = len(str2)
if N % M != 0:
return False
for i in range(N):
if str1[i] != str2[i % M]:
return False
return True
|
11344 | Validation/png/11344.png | # Write a python function to check if roots of a quadratic equation are reciprocal of each other or not.
def Check_Solution(a, b, c):
if a == c:
return "Yes"
else:
return "No"
|
11642 | Validation/png/11642.png | # Write a function to find the nth delannoy number.
def dealnnoy_num(n, m):
if m == 0 or n == 0:
return 1
return dealnnoy_num(m - 1, n) + dealnnoy_num(m - 1, n - 1) + dealnnoy_num(m, n - 1)
|
11673 | Validation/png/11673.png | # Write a function to convert camel case string to snake case string.
def camel_to_snake(text):
import re
str1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", text)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", str1).lower()
|
11834 | Validation/png/11834.png | def fun152(string):
length = len(string)
new = ''
for i in range(length):
ch = ord(string[i])
if ch >= 65 and ch <= 90:
new = new + chr(ch + 32)
else:
new = new + chr(ch)
return new
|
11332 | Validation/png/11332.png | # Write a python function to convert the given string to upper case.
def is_upper(string):
return string.upper()
|