Write a program in python to print even and odd number between 1 to 50
CODE:
num = int(input(" Please Enter any Maximum Number: "))
print(" Odd Number")
for number in range(1, num + 1):
    if(number % 2 != 0):
        print("{0}".format(number))
print(" Even Number")
for number in range(1, num+1):
    if(number % 2 == 0):
        print("{0}".format(number))
Write a program in python to print
factorial of number
CODE:
import math  
def fact(n):  
    return(math.factorial(n))  
num = int(input("Enter the number:"))  
f = fact(num)  
print("Factorial of", num, "is", f)  
Write a program in python to print
Fibonacci series between 1 to 20
CODE:
n = int(input("Enter the value of 'n': "))
a = 0
b = 1
sum = 0
count = 1
print("Fibonacci Series: ", end = " ")
while(count <= n):
  print(sum, end = " ")
  count += 1
  a = b
  b = sum
  sum = a + b
Write a program in python to count a
element in a list
CODE:
# declare list of items
elem_list = [1, 2, 3, 4]
 # printing the list
print(elem_list)
# using the len() which return the number
# of elements in the list
print("No of elements in list are:", len(elem_list))
Write a program in python to implement
tuple data types
CODE:
my_tuple=(1,2,3)
print(my_tuple)
CODE:
my_tuple=(1,'XYZ',3,4)
print(my_tuple)
CODE:
my_tuple=("BWU",[2,4,6],[1,3,5])
print(my_tuple[0][2])
print(my_tuple[1][1])
CODE:
my_tuple=(3,4,5,"XYZ")
print(my_tuple)
CODE:
my_tuple=('S','H','R','U','T','I')
print(my_tuple[0])
print(my_tuple[5])
CODE:
my_tuple=('a','b','c','d','e','f','g','h')
print(my_tuple[1:4])
print(my_tuple[ :-6])
print(my_tuple[6: ])
print(my_tuple[ : ])
Write a program in python to
implement dictionary data types
CODE:
my_dict={1:'apple',2:'ball'}
print(my_dict)
CODE:
my_dict=dict({1:'apple',2:'ball'})
print(my_dict)
CODE:
my_dict=dict([(1,'apple'),(2,'ball')])
print(my_dict)
CODE:
my_dict['age']=19
print(my_dict['age'])
CODE:
my_dict={'name':'XYZ','age':19}
print(my_dict['name'])
print(my_dict['age'])
CODE:
my_dict['address']='barasat'
print(my_dict)
CODE:
square={1:1,2:4,3:9,4:16,5:25}
print(square.pop(4))
print(square)
print(square.popitem())
print(square)
square.clear()
del square
Write a program in c to
implement Run-length encoding
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_RLEN 50
char* encode(char* src)
{
    int rLen;
    char count[MAX_RLEN];
    int len = strlen(src);
    char* dest = (char*)malloc(sizeof(char) *
(len * 2 + 1));
    int i, j = 0, k;
    for (i = 0; i < len; i++) {
        dest[j++] = src[i];
        rLen = 1;
        while (i + 1 < len && src[i]
== src[i + 1]) {
            rLen++;
            i++;
        }
        sprintf(count, "%d", rLen);
        for (k = 0; *(count + k); k++, j++) {
            dest[j] = count[k];
        }
    }
    dest[j] = '\0';
    return dest;
}
int main()
{
    char str[] =
"wwwwaaadexxxxxxywwwwwwwww";
    char* res = encode(str);
    printf("%s", res);
    getchar();
}
Write a program in python to
compute sum of squares of first n numbers.
CODE:
def SumofSquares(n):
    s=0
    for i in range(n+1):
        s+=i**2
    return s
n=int(input("enter n: "))
print("sum of squares of first {} natural numbers: ".format(n),SumofSquares(n))
Take a input of radius from
user & calculate the area & circumferences of the circle
CODE:
print("Enter Radius of Circle: ")
r = float(input())
pie = 3.14
c = 2 * pie * r
print("\nCircumference = ", c)
Write a program in python to
print RGB value of a different color
CODE:
#RGB_To_GrayScale (8bit_To_8bit)
from PIL import Image
img = Image.open("sample_data/tree-736885-340.jpg')
ingGray ing.convert("1")
ingGray.save('sample_data/tree-736885_340_new2.jpg')
CODE:
#RGB_To_GrayScale(8bit_To_8bit)
from PIL import Image
img Image.open("sample_data/tree-736885340.jpg')
imgGray =img.convert("1")
imgGray.save('sample_data/tree-736885_340_new2.jpg')
CODE:
RGB_To_GrayScale(8bit_To_8bit)
from PIL import Image
img Image.open("sample_data/tree-736885_348.jpg')
imgGray img.convert("L")
imgGray.save('sample_data/tree-736885_348_new.jpg')
CODE:
#RGB_To_GrayScale (8bit_To_8bit)
from PIL import Image
img Image.open('sample_data/tree-736885_340.jpg")
imgGray img.convert("L") imgGray.save('sample_data/tree-736885_348_new.jpg)
Post a Comment