CT Group of Institutions, Maqsudan
Experiment Title:Write a program to demonstrate different number d
types in Python.
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 1 Department: [Link] CSE Semester: 5TH
Write a program to demonstrate different number data types in Python.
Code:
num1=10
num2=45.56
num3=complex(a,b)
print("Type of num1 is:", type(num1))
print("Type of num2 is:", type(num2))
print("Type of num3 is:", type(num3))
Output:
Page|1 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a program to perform different Arithmetic
Operations on numbers in Python.
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 2 Department: [Link] CSE Semester: 5TH
Aim: Write a program to perform different Arithmetic Operations on numbers in
Python.
Code:
num1=int(input("Enter num1 :"))
num2=int(input("Enter num2 :"))
a=num1+num2
b=num1-num2
c=num1*num2
d=num1/num2
e=num1%num2
print("Addition of two numbers is:",a)
print("Subtraction of two numbers is:",b)
print("Multiplication of two numbers is:",c)
print("Division of two numbers is:",d)
print(" Remainder is:",e)
Output:
Page|2 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a program to create, concatenate and print a string
and accessing sub-string from a given string.
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 3 Department: [Link] CSE Semester: 5TH
Aim: Write a program to create, concatenate and print a string and accessing sub-
string from a given string.
Code:
Str1=Str(input(“Enter First String:”))
Str1=Str(input(“Enter First String:”))
Concatenate=Str1+ “” +Str2
Print(“The String is:Concatenate)
Print(“The Substring is:”, Concatenate[1:6])
Output:
Page|3 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a python script to print the current date in the
following format “Sun May 29 02:26:23 IST 2017”
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 4 Department: [Link] CSE Semester: 5TH
Aim: Write a python script to print the current date in the following format “Sun
May 29 02:26:23 IST 2017”
Code:
import time
ltime=[Link]();
print([Link]("%a %b %d %H: %M: %S %Z %Y", ltime));
print(ltime)
Output:
Page|4 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a program to create, append, and remove lists in
python
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 5 Department: [Link] CSE Semester: 5TH
Aim: Write a program to create, append, and remove lists in python.
Code:
a=[1,78,20,"Python"]
print("length of list is:", len(a)+1)
[Link](98)
print("New list A is:",list(a))
[Link](78)
print("updated list is:",list(a))
list=[1,"asia",3.2,"cup"]
[Link] (2023)
print(list)
[Link](3.2)
print(list)
Output:
Page|5 Roll no:2123673
Page|6 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a program to demonstrate working with tuples in
python.
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 6 Department: [Link] CSE Semester: 5TH
Aim: Write a program to demonstrate working with tuples in python.
Code:
a=input("enter your tuple :").split(",")#first tuple
print('first Tuple is:-',a)
print('value of tuple at index 6 is:-',a[6])
print("length of a tuple is:-",len(a))
print("repetition of tuple: ",a*2)
print([Link](9))
b=(40,9,32.5,12.98,65,98) #second tuple
print("second tuple is:-",b)
print("maximum value in tuple: ",max(b))
print("minimum value in tuple: ",min(b))
print("sum of tuple is:",sum(b))
print("tuple after sorting",sorted(b))
c=('Raju')
print(tuple(c))
Output:
Page|7 Roll no:2123673
Page|8 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a program to demonstrate working with dictionaries
in python
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 7 Department: [Link] CSE Semester: 5TH
Aim: Write a program to demonstrate working with dictionaries in python.
Code:
dic1 = {1: "Hello, ", 2: "welcome ", 3: "to ", 4: "python"}
dic2 = [Link]()
print(dic2)
[Link]()
print(dic1)
print([Link](1))
print([Link]())
print([Link]())
[Link](4)
print(dic2)
[Link]()
print(dic2)
[Link]({3: "To"})
print(dic2)
print([Link]())
Output:
Page|9 Roll no:2123673
Page|10 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a python program to find largest of three numbers
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 8 Department: [Link] CSE Semester: 5TH
Aim: Write a python program to find largest of three numbers.
Code:
a=int(input("Enter number 1:"))
b=int(input("Enter number 2:"))
c=int(input("Enter number 3:"))
if(a>b)and(a>c):
print("number 1 is largest")
if(b>a) and (b>c):
print("number 2 is largest")
else:
print("number 3 is largest")
Output:
Page|11 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a Python program to convert temperatures to and
from Celsius, Fahrenheit. [ Formula: c/5 = f-32/9]
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 9 Department: [Link] CSE Semester: 5TH
Aim: Write a Python program to convert temperatures to and from Celsius,
Fahrenheit. [ Formula: c/5 = f-32/9]
Code:
celsius = float(input("Enter the temperature in Celsius :"))
f=float(input("Enter the temperature in Faherenheit :"))
fahrenheit = celsius*(9/5)+32
print("The temperature converted in fahrenheit is :",fahrenheit)
celsius=(f-32 )* 5/9
print("The temperature converted in celsius is :",celsius)
Output:
Page|12 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title: Write a Python program to construct the following pattern,
using a nested for loop .
Laboratory: Python Lab (BTCS 513-18)
Experiment No: 10 Department: [Link] CSE Semester: 5TH
Aim: Write a Python program to construct the following pattern, using a nested for
loop .
Code:
n=4
for i in range(0, n):
for j in range(0, i + 1):
print("*", end=' ')
print(" ")
for i in range(n , 0, -1):
for j in range(0, i - 1):
print("*", end=' ')
print(" ")
print("*")
Output:
Page|13 Roll no:2123673
Page|14 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title: Write a Python script that prints prime numbers less than
20
Laboratory: Python Lab (BTCS 513-18)
Experiment No:11 Department: [Link] CSE Semester: 5TH
Aim: Write a Python script that prints prime numbers less than 20.
Code:
def is_prime(number):
if number <= 1:
return False
if number <= 3:
return True
if number % 2 == 0 or number % 3 == 0:
return False
i=5
while i * i <= number:
if number % i == 0 or number % (i + 2) == 0:
return False
i += 6
return True
def print_primes_less_than_20():
for num in range(2, 20):
if is_prime(num):
print(num)
print_primes_less_than_20()
Output:
Page|15 Roll no:2123673
Page|16 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a python program to find factorial of a number using
Recursion.
Laboratory: Python Lab (BTCS 513-18)
Experiment No:12 Department: [Link] CSE Semester: 5TH
Aim: Write a python program to find factorial of a number using Recursion.
Code:
def recur_fact(n):
if n==1:
return n
else:
return n*recur_fact(n-1)
num=int (input("enter a number: "))
if num<0:
print("sorry, factorial does not exist for negative numbers")
elif num==0:
print("the factorial of 0 is 1")
else:
print("the factorial of ", num,"is", recur_fact(num))
Output:
Page|17 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a program that accepts the lengths of three sides of a
triangle as inputs. The program output should indicate whether or not the
triangle is a right triangle (Recall from the Pythagorean Theorem that in a
right triangle, the square of one side equals the sum of the squares of the other
two sides).
Laboratory: Python Lab (BTCS 513-18)
Experiment No:13 Department: [Link] CSE Semester: 5TH
Aim: Write a program that accepts the lengths of three sides of a triangle as inputs.
The program output should indicate whether or not the triangle is a right triangle
(Recall from the Pythagorean Theorem that in a right triangle, the square of one side
equals the sum of the squares of the other two sides).
Code:
base=float(input("Enter length of base: "))
perp=float(input("Enter length of perpendicular"))
hypo=float(input("Enter length of hypotenuse: "))
if hypo**2==((base**2))+((perp**2)):
print("It's a right triangle")
else:
print("It's not a right triangle")
Output:
Page|18 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a python program to define a module to find
Fibonacci Numbers and import the module to another program.
Laboratory: Python Lab (BTCS 513-18)
Experiment No:14 Department: [Link] CSE Semester: 5TH
Aim: Write a python program to define a module to find Fibonacci Numbers and
import the module to another program.
Code:
Module file:
def fib(num):
f1= 0
f2=1
print(f1,f2, end=" ")
for i in range(num):
f3=f1+f2
print(f3, end=" ")
f1=f2
f2=f3
Main file:
import fib
n=int(input("Enter number:"))
[Link](n)
Output:
Page|19 Roll no:2123673
Page|20 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a python program to define a module and import a
specific function in that module to another program.
Laboratory: Python Lab (BTCS 513-18)
Experiment No:15 Department: [Link] CSE Semester: 5TH
Aim: Write a python program to define a module and import a specific function in
that module to another program.
1. Module file sub:
def sub(a,b):
c=a-b
return c
2. Module file add:
def add(a,b):
c=a+b
return c
3. Main file:
import sub
import add
num1= int(input("enter first number"))
num2= int(input("enter second number"))
print("subtraction of two numbers is:",[Link](num1,num2))
print("addition of two numbers is:", [Link](num1,num2))
Output:
Page|21 Roll no:2123673
Page|22 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:Write a script named [Link]. This script should prompt
the user for the names of two text files. The contents of the first file should be
input and written to the second file.
Laboratory: Python Lab (BTCS 513-18)
Experiment No:16 Department: [Link] CSE Semester: 5TH
Aim: Write a script named [Link]. This script should prompt the user for the
names of two text files. The contents of the first file should be input and written to
the second file.
Code:
Output:
Page|23 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:
Laboratory: Python Lab (BTCS 513-18)
Experiment No:17 Department: [Link] CSE Semester: 5TH
Page|24 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:
Laboratory: Python Lab (BTCS 513-18)
Experiment No:18 Department: [Link] CSE Semester: 5TH
Page|25 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:
Laboratory: Python Lab (BTCS 513-18)
Experiment No:19 Department: [Link] CSE Semester: 5TH
Page|26 Roll no:2123673
CT Group of Institutions, Maqsudan
Experiment Title:
Laboratory: Python Lab (BTCS 513-18)
Experiment No:20 Department: [Link] CSE Semester: 5TH
Page|27 Roll no:2123673