PRACTICAL FILE
Python Programming
(IT551c)
B.E. (IT) 5th Semester
Submitted To: Submitted By:
Sukhvir Sir Shubham Kumar
UE228093
IT SECTION 2
Department Of Information Technology
University Institute Of Engineering & Technology
Panjab University,Chandigarh
List Of Programs
[Link] LIST OF PROGRAM DATE OF DATE OF REMARK
PERFORM SUBMISSION
1. Write a program to perform logical AND ,
OR and NOT operations.
2. Write a Program to print sin, cos, tan of
angle input as degrees.
3. Write a program to print an even number
until given n.
4. Write a Program to find the product of
digits of a number.
5. Write a Program to print first n terms of a
fibonacci sequence.
6. Write a Program to print first n terms of a
fibonacci sequence using a Dictionary.
7. Write a Program to find factorial without
recursion.
8. Write a Program to find factorial using
recursion.
9. Write a program to perform find, rfind and
count in strings.
10. Write a program to find indexes of all
occurances of a substring in a given
string.
11. Write a program to count all occurrences
of a substring in a given string.
12. Write a program to find sum of all natural
number between 1 to n using recursion.
13. Write a program to find the reverse of a
number.
14. Write a program to find Contact Number
Using a Dictionary.
[Link] a program to perform logical AND , OR and NOT
operations.
a = 5
b = 6
print(bool(a and b))
print(bool(a or b))
print(a and b)
print(a or b)
print(not(a and b))
OUTPUT:
[Link] a Program to print sin, cos, tan of angle input as
degrees.
import math
x = 90
print([Link](x))
y = [Link](x)
print("radians",y)
print("sin",int([Link](y)))
print("cos",int([Link](y)))
print("tan",int([Link](y)))
OUTPUT:
[Link] a program to print an even number until given n.
n = int(input("Enter Any Number:"))
for i in range(1, n + 1):
if i % 2 == 0:
print(i)
OUTPUT:
[Link] a Program to find the product of digits of a number.
N = int(input("Enter N:"))
multiply = 1
while N:
multiply = multiply * int(N % 10)
N = N // 10
print(f"multiplication of number are:", multiply)
OUTPUT:
[Link] a Program to print first n terms of a fibonacci
sequence.
nterms = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto", nterms, ":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
OUTPUT:
[Link] a Program to print first n terms of a fibonacci
sequence using a Dictionary.
num = int(input("Enter n:"))
dic = {0: 0, 1: 1}
print("Fibonacci(", 0, ") terms =", dic[0])
print("Fibonacci(", 1, ") terms =", dic[1])
for i in range(2, num):
dic[i] = dic[i - 1] + dic[i - 2]
print("Fibonacci(", i, ") terms =", dic[i])
OUTPUT:
[Link] a Program to find factorial without recursion.
import math
a = int(input("Enter a number: "))
print([Link](a))
OUTPUT:
[Link] a Program to find factorial Using recursion.
def fun(n):
if n == 0:
return 1
else:
return n * fun(n - 1)
num = int(input("Enter the number: "))
print(fun(num))
OUTPUT:
[Link] a program to perform find, rfind and count in strings.
Str1 = "shubhamshubhamshubham"
Str2 = "sh"
print([Link](Str2))
Str1 = "UIET Panjab University UIET Chandigarh UIET"
Str2 = "UIET"
print("First Position:", [Link](Str2), "Count:",
[Link](Str2))
print([Link](Str2))
OUTPUT:
[Link] a program to find indexes of all occurances of a
substring in a given string.
str1 = input("Enter A String:")
str2 = input("Enter A Substring That You Want To Search:")
i = 0
while True:
index = [Link](str2, i)
if index == -1:
# print("No Match")
break
# print("Index")
print("{} occurs at index {}".format(str2, index))
i = index + 1
OUTPUT:
[Link] a program to count all occurrences of a substring
in a given string.
s = input("Enter String:")
sub = input("Enter Substring:")
print([Link](sub))
l = []
l = [Link](" ")
count = 0
for i in l:
if i == sub:
count += 1
OUTPUT:
[Link] a program to find sum of all natural number between
1 to n using recursion.
def recur_sum(n):
if n <= 1:
return n
else:
return n + recur_sum(n - 1)
num = int(input("Enter the number: "))
if num < 0:
print("Enter a positive number")
else:
print("The sum is", recur_sum(num))
OUTPUT:
[Link] a program to find the reverse of a number.
num = int(input("Enter the Number: "))
reversed_num = 0
while num != 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
print("Reversed Number: " + str(reversed_num))
OUTPUT:
[Link] a program to find Contact Number Using a
Dictionary.
name = ("Shubham", "Muskan", "Aaditya", "Saloni")
contact = (121, 123, 145, 432)
d = dict(zip(name, contact))
x = input("Enter name to find His/Her Contact Number:")
print(d[x])
Information = {
"Shubham": 121,
"Muskan": 123,
"Aaditya": 145,
"Saloni": 432
}
name = input("Enter name to find His/Her Contact Number:")
print(Information[name])
OUTPUT: