Categories:Viewed: 3 - Published at: a few seconds ago

Write a Python Program to print the LCM of Two Numbers

def lcm(a,b):
    lcm.multiple=lcm.multiple+b
    if((lcm.multiple % a == 0) and (lcm.multiple % b == 0)):
        return lcm.multiple
    else:
        lcm(a, b)
    return lcm.multiple
lcm.multiple=0
a=4
b=7
if(a>b):
    LCM=lcm(b,a)
else:
    LCM=lcm(a,b)

print(LCM)

Write a Python function to print the GSD of Two Numbers

def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b,a%b)

Write a Python function to Find if a Number is Prime or Not Prime

def check(n, div = None):
    if div is None:
        div = n - 1
    while div >= 2:
        if n % div == 0:
            print("Number not prime")
            return False
        else:
            return check(n, div-1)
    else:
        print("Number is prime")
        return 'True'

Write a Python function to Find the Power of a Number Using Recursion

def power(base,exp):
    if(exp==1):
        return(base)
    if(exp!=1):
        return(base*power(base,exp-1))

Write a Python function to Find the Total Sum of a Nested List Using Recursion

def sum1(lst):
    total = 0
    for element in lst:
        if (type(element) == type([])):
            total = total + sum1(element)
        else:
            total = total + element
    return total

### Write a Python function to Count and print the Number of Vowels Present in a String using Sets

def count_vowels(s): count = 0 vowels = set("aeiou") for letter in s: if letter in vowels: count += 1 return count

### Write a Python Program to prints Common Letters in Two Input Strings

s1='python' s2='schoolofai' a=list(set(s1)&set(s2)) print("The common letters are:") for i in a: print(i)

### Write a Python Program that Prints which Letters are in the First String but not in the Second

s1='python' s2='schoolofai' a=list(set(s1)-set(s2)) print("The letters are:") for i in a: print(i)

### Write a Python Program to Concatenate Two Dictionaries Into One

def concat_dic(d1, d2): return d1.update(d2)

### Write a Python Program to Multiply All the Items in a Dictionary

def mul_dict(d): tot=1 for i in d:
tot=tot*d[i] return tot

### Write a Python Program to Remove the Given Key from a Dictionary

def removeitemdict(d, key): if key in d: del d[key] else: print("Key not found!") exit(0)

### Write a Python Program to Map Two Lists into a Dictionary

def map_dict(keys, values): return dict(zip(keys,values)) ```