0% found this document useful (0 votes)
0 views10 pages

Python Pratice Programs Xi

The document contains a series of Python practice programs that demonstrate various programming concepts. Each question includes a source code example, user input prompts, and corresponding output for tasks such as calculating simple interest, checking for palindromes, generating Fibonacci series, and more. The programs cover basic operations, data structures, and control flow in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views10 pages

Python Pratice Programs Xi

The document contains a series of Python practice programs that demonstrate various programming concepts. Each question includes a source code example, user input prompts, and corresponding output for tasks such as calculating simple interest, checking for palindromes, generating Fibonacci series, and more. The programs cover basic operations, data structures, and control flow in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

PYTHON PRATICE

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

print('The simple interest is : ', SI)

OUTPUT:-
Enter the principal amount in : 5000

Enter the rate of interest: 7.4

Enter the time in years: 2

The simple interest is : 740.0


Q2 : Write a program that reads a string and checks
whether it is a palindrome string or not.
SOURCE CODE:-
string=input('Enter a string:')
length=len(string)
mid=length//2
rev=-1
for a in range(mid):
if string[a]==string[rev]:
print(string,'is a palindrome.')
break
else:
print("string is not palindrome")

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

Sum of 5 terms is: 35


Q5: Write a program to find the largest among the three
integers.
SOURCE CODE:-
a=int(input('Enter the first integer:'))
b=int(input('Enter the second integer:'))
c=int(input('Enter the third integer:'))

if a>b and a>c:


print(a, 'is the largest integer')
if b>a and b>c:
print(b, 'is the largest integer')
if c>a and c>b:
print(c, 'is the largest integer')

OUTPUT:-
Enter the first integer:50

Enter the second integer:25

Enter the third integer:69

69 is the largest integer


Q6: Write Python program that reads a line and prints its
statistics like:
 The number of uppercase letters:
 The number of lowercase letters:
 The number of alphabets:
 The number of digits:

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

print('Number of uppercase letters are:',uppercount)


print('Number of lowercase letters are:',lowercount)
print('Number of alphabets are:',alphacount)
print('Number of digits are:',digitcount)

OUTPUT:-
Enter a line:Host and parasite tend to coevolve

Number of uppercase letters are: 1

Number of lowercase letters are: 28

Number of alphabets are: 29

Number of digits are: 0


Q7: Write a program to search an element from the given
list.
SOURCE CODE:-
L=eval(input("Enter the elements:"))
n=len(L)
flag =1
s = int(input("Enter the element to be searched:"))
for i in range(0,n-1):
if(L[i]==s):
flag=1
break;
else:
flag=0

if flag==1:
print("Element found")
else:
print("Elemnet not found")

OUTPUT:-
Enter the elements:[1, 2, 3, 4, 5]

Enter the element to be searched:4

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

Entered Numbers are:

('58', '45', '12', '78', '20')


Q9: Write a Program to store students’ details like
admission number, roll number, name and percentage in a
dictionary and display information on the basis of
admission number.
SOURCE CODE:-
record = dict ()
i=1
n= int (input ("How many records u want to enter: "))
while(i<=n):
Adm = input("Enter Admission number: ")
roll = input("Enter Roll Number: ")
name = input("Enter Name :")
perc = float(input("Enter Percentage : "))
t = (roll,name, perc)
record[Adm] = t
i = i + 1
Nkey = record.keys()
for i in Nkey:
print("\nAdmno- ", i, " :")
r = record[i]
print("Roll No\t", "Name\t", "Percentage\t")
for j in r:
print(j, end = "\t")
OUTPUT:-
Q10: Write a Python Program Input three angles and
determine if they form a triangle or not.
SOURCE CODE:-
r=float(input('Enter the radius of the circle:'))
print('1.Calculate perimeter')
print('2.Calculate area')
choice=int(input('Enter your choice (1 or 2):'))
if choice==1:
peri=2*3.14159*r
print('Perimeter of the circle with radius',r,':',peri)
else:
area=3.14159*r*r
print('Area of the circle of the radius',r,':',area)

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

You might also like