Python Pratice Programs Xi
Python Pratice Programs Xi
PROGRAMS
Q1: Write a program to calculate simple interest.
Source Code:-
P=float(input('Enter the principal amount in : '))
R=float(input('Enter the rate of interest: '))
T=float(input('Enter the time in years: '))
SI=(P*R*T)/100
OUTPUT:-
Enter the principal amount in : 5000
OUTPUT:-
Enter a string:MALYALAM
MALYALAM is a palindrome.
Q3: Write a Python script to print Fibonacci series’ first 20
elements.
SOURCE CODE:-
first=0
second=1
print(first, end=' ')
print(second,end=' ')
for a in range(1,9):
third=first+second
print(third,end=' ')
first,second=second,third
OUTPUT:-
0 1 1 2 3 5 8 13 21 34
Q4: Write a python script to calculate the sum of the
following series:
S=(1)+(1+2)+(1+2+3)+……+(1+2+3+….+n)
SOURCE CODE:-
Sum=0
n=int(input('How many terms?'))
for a in range(2,n+2):
term=0
for b in range(1,a):
term+=b
print('Term',(a-1),':',term)
Sum+=term
print('Sum of',n,'terms is:',Sum)
OUTPUT:-
How many terms?5
Term 1 : 1
Term 2 : 3
Term 3 : 6
Term 4 : 10
Term 5 : 15
OUTPUT:-
Enter the first integer:50
SOURCE CODE:-
line=input('Enter a line:')
lowercount=uppercount=0
digitcount=alphacount=0
for a in line:
if a.islower():
lowercount+=1
elif a.isupper():
uppercount+=1
elif a.isdigit():
digitcount+=1
if a.isalpha():
alphacount+=1
OUTPUT:-
Enter a line:Host and parasite tend to coevolve
if flag==1:
print("Element found")
else:
print("Elemnet not found")
OUTPUT:-
Enter the elements:[1, 2, 3, 4, 5]
Element found
Q8: Write a Program to accept values from user and create
a tuple.
SOURCE CODE:-
t=tuple()
n=int(input("How many values you want to enter: "))
for i in range(n):
a=input("Enter Number: ")
t=t+(a,)
print("Entered Numbers are: ")
print(t)
OUTPUT:-
How many values you want to enter: 5
Enter Number: 58
Enter Number: 45
Enter Number: 12
Enter Number: 78
Enter Number: 20
OUTPUT:-
Enter the radius of the circle:5
1.Calculate perimeter
2.Calculate area
Enter your choice (1 or 2):1
Perimeter of the circle with radius 5.0 : 31.4159
1.Calculate perimeter
2.Calculate area
Enter your choice (1 or 2):2
Area of the circle of the radius 5.0 : 78.53975