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

Write a python program which takes input a list and print reverse output

lst = eval(input("Enter list"))
print(lst[::-1]) 

Write a python function which takes sentence as input and remove vowels from a sentence

sentence = input("Enter a sentence : ")

def fn(sentence):
    vowels = 'aeiou'
    return ''.join([ l for l in sentence if l not in vowels])

Write a python function which takes two list of same length as input and return a dictionary with one as keys and other as values.

keys = eval(input("Enter key list : "))
values = eval(input("Enter value list : "))
def fn(keys, values):
    return { keys[i] : values[i] for i in range(len(keys)) }

Write a python function that takes an integer as input and returns the factorial of that number

def factorial(n): 

    # single line to find factorial 
    return 1 if (n==1 or n==0) else n * factorial(n - 1); 

Write a python function that takes input radius and return area of circle

def findArea(r): 
    PI = 3.142
    return PI * (r*r);

Write a python funtion that takes input principle, rate, time and calculate compound intrest

def compound_interest(principle, rate, time):
    # Calculates compound interest  
    Amount = principle * (pow((1 + rate / 100), time)) 
    CI = Amount - principle 
    print("Compound interest is", CI) 

Write a python program to print the ascii value of input character

character = input(" Enter Character :")
print(f"Ascii value of character {character} is : " , ord(character))

Write a python program that takes input an integer and find sum of series with cubes of first n natural numbers using list comprehension which ta

N = int(input("Enter Integer "))
lst = [i**3 for i in range(1, N + 1)]
print(sum(lst)) 

Write a python function that takes list as an input and converts it into tuple

def convert(list): 
    return tuple(list)

Write a Python program to get a list, sorted 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)

print(sort_list_last([(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]))

Write a python program to concatenate two dictionaries

d1 = {'a' : 1 ,'b' : 2}
d2 = {'c' : 1 ,'d' : 2}
d3 = {**d1,**d2}
print(d3)

Write a Python program to print the length of a set.

#Create a set
seta = set([5, 10, 3, 15, 2, 20])
#Find the length use len()
print(len(seta))

Write a python program that takes two sets as input and print the common elements

s1 = eval(input("Enter set 1 "))
s2 = eval(input("Enter set 2 "))
print(s1.intersection(s2))

Write a python program which takes input a list and prints the mean of elements within the list

s1 = eval(input("Enter list "))
mean = sum(s1) / len(s1) 
print("Mean of sample is : " + str(mean)) 

Write a python program which takes input a list and prints the standard deviation of elements within the list

mean = sum(s1) / len(s1) 
variance = sum([((x - mean) ** 2) for x in s1]) / len(s1) 
res = variance ** 0.5
print("Standard deviation of sample is : " + str(res)) 

Write a python program which prints a random number

import random
n = random.random()
print(n)