Python Practical
Python Practical
f=0
print(("Cel = Fah"))
for c in range(0,101,1):
f = (c*9/5)+32
print(c, " = ", f)
import math
x = float(0)
print("x = sin \t cos \t tan")
while x<=10:
print(x, " = ", round(math.sin(x),4), " | ",round(math.cos(x),4),
" | ",round(math.tan(x),4))
x = round(x+float(0.2),1)
3. Program to read an integer value and print Leap
year or not:
for i in range(0,n+1,1):
for j in range(0,i,1):
print("*",end="")
print()
5. Function that takes integer n as input and calculates
the value of 1 + 1/1! + 1/2! + 1/3! + … + 1/n!
import math
def calculate():
n = int(input("Enter number = "))
series_sum = 0.0
for i in range(1, n+1, 1):
series_sum += 1/math.factorial(i)
return series_sum
result = calculate()
print("Result of series = ", result)
import math
def fact():
n = int(input("Enter number = "))
fact = 1
for i in range(1, n+1):
fact = fact*i
print("Factorial of ", n, " = ", fact)
fact()
7. Function that takes string input and checks
Palindrome or not:
def check():
str = input("Enter string = ")
length = len(str)
for i in range(length):
if str[i] != str[length-1-i]:
return False
return True
if check():
print("String is palindrome...... ")
else:
print("String is not palindrome...... ")
def list():
str = input("Enter string = ")
list = []
length = len(str)
for i in range(length):
list.append(str[i])
print("List = ", list)
list()
9. Program to generate Fibonacci series:
for i in range(1,n+1):
if n%i == 0:
if i == n:
print(i)
else:
print(i, end=", ")
13. Program to calculate Greatest Common
Difference (GCD) of two numbers:
def gcd(a,b):
if b==0:
return a
else:
return gcd(b, a%b)
result = gcd(a,b)
print("Greatest Common Difference between ",a ," ,",b ," =
",result)