Python (Lab1+2)
Python (Lab1+2)
Python Programming
(IT551c)
B.E. (IT) 5th Semester
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:
print(math.sin(x))
y = math.radians(x)
print("radians",y)
print("sin",int(math.sin(y)))
print("cos",int(math.cos(y)))
print("tan",int(math.tan(y)))
OUTPUT:
OUTPUT:
4.Write 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
OUTPUT:
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:
6.Write a Program to print first n terms of a fibonacci
sequence using a Dictionary.
OUTPUT:
7.Write a Program to find factorial without recursion.
import math
OUTPUT:
def fun(n):
if n == 0:
return 1
else:
return n * fun(n - 1)
Str1 = "shubhamshubhamshubham"
Str2 = "sh"
print(Str1.count(Str2))
OUTPUT:
10.Write a program to find indexes of all occurances of a
substring in a given string.
OUTPUT:
s = input("Enter String:")
sub = input("Enter Substring:")
print(s.count(sub))
l = []
l = s.split(" ")
count = 0
for i in l:
if i == sub:
count += 1
OUTPUT:
def recur_sum(n):
if n <= 1:
return n
else:
return n + recur_sum(n - 1)
if num < 0:
print("Enter a positive number")
else:
print("The sum is", recur_sum(num))
OUTPUT:
while num != 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
OUTPUT:
14.Write a program to find Contact Number Using a
Dictionary.
Information = {
"Shubham": 121,
"Muskan": 123,
"Aaditya": 145,
"Saloni": 432
}
OUTPUT: