Index
Index
S. Practical Sign
No.
Generate the following
1 patterns using
Nested loop
Write a program to input the
2 value of x and n and print the
sum of the following series:
Determine whether a number
3 is a perfect number,
Armstrong number or a
palindrome
Input a number and check if
4 number is prime or
composite:
Display the terms of the
5 Fibonacci series
Compute the greatest
6 common divider and least
common multiple of two
integers
Write a python code to input
7 two unequal positive numbers
and check whether they are
perfect square numbers or
not
Write a python code to input
8 three numbers
and check whether they are
equal or not
A bank announces new rates
9 of term deposit schemes for
the general customers and
senior citizens
Write a python program by
10 using user’s choice to perform
the following task by taking
suitable variables
Pattern 1 code:
# WAP to get the following output:
n=int (input ("Enter the nod of rows "))
for I in range (1, n+1):
for j in range (I):
print ("*,” end='')
print ()
Output:
Enter the nod of rows 6
*
**
***
****
*****
******
Pattern 2 code:
# WAP to get the following sequence
n=int (input ("Enter the nod of rows"))
for I in range (n,0, -1):
for j in range (1, i+1,):
print(end='')
print ()
Output:
Enter the nod of rows 6
123456
12345
1234
123
12
1
Pattern 3 code:
# WAP to get the following sequence
for I in range (65,73):
for j in range (65, i):
print(chr(j), end='')
print ()
Output:
A
AB
ABC
ABCD
ABCDE
ABCDEF
ABCDEFG
Output:
Enter value of x 5
Enter the value of n 4
Sum of first 4 terms 781
2.1-x+x2-x3+…. +an
CODE:
x=int (input ("Enter value of x"))
n=int (input ("Enter the value of n"))
s=0
sign=+1
for a in range (n+1):
term=(x**a) *sign
s+=term
sign*=-1
print ("Sum of first", n, "terms ", s)
Output:
Enter value of x 5
Enter the value of n 4
Sum of first 4 terms 521
3.x-x2/2+x3-x4/4+x5/5-x6/6
Code:
x=int (input ("Enter value of x"))
n=6
s=0
sign=+1
for a in range (1, n+1):
term=((x**a)/a) *sign
s+=term
sign=-1
print ("Sum of first", n," terms", s)
Output
Enter value of x 2
Sum of first 6 terms -23.733333333333334
3.Determine whether a
number is a perfect number,
an angstrom no or a
palindrome:
Code:
n=int (input (“Enter any number”))
#for perfect number
sum1=0
for I in range (1, n):
if (n % I==0):
sum1=sum1+i
(sum1==n)
print (“The number,’ n, ’is a perfect number’)
else:
print (“The number is, n, ‘is not a perfect
number’)
# for angstrom number:
der=Len(str(n))
n=0
np=n
while temp>0
digit=temp % 10
sum=digit**order
temp//=10
n==sum:
print (“The number,” n,” is an angstrom
number”)
else:
print (“The number,” n, “is not an angstrom
number”)
# for palindrome number
rev=0
number=n
while (number! = 0):
digit=number % 10
number=number//10
if rev == number:
print (n, “Is a palindrome”)
else:
print (n,” Is not a palindrome”)
Output:
Enter any number 343
The number 343 is not a perfect number
The number 343 is not an angstrom number
The number 343 is a palindrome
Output:
How many terms? 8
Fibonacci series up to 8
0
1
1
a
3
5
8
13
Output:
Enter any number 12
Enter any number 18
The greatest common divisor, 6
The lcm is 36
import math
A=int (input (“Enter any positive number”))
B=int (input (“Enter any positive number other
than A”))
Square root 1=math.sqrt (A)
Square root 2=math.sqrt(B)
if typ(square root 1)==int:
print(A,”Is a perfect square”)
else:
print(A,”Is not a perfect square”)
if typ(square root 2)==int:
print(B,”Is a square root”)
else:
print(B,”Is not a square root”)
if A and B <0:
print(“please enter valid no:”)
Output:
Enter any positive no:36
Enter any positive no other than A : 25
36 is a perfect square
25 is a perfect square
9. Write a program to
accept the sum in terms of
deposit scheme, age of
customer and the term.
Code:
a=int(input(“Enter the sum in deposit))
b=int(input(“Enter the age of the customer))
c=int(input(“Enter the term))
if b<60:
if c==1:
x=6.0
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
elif (c==2):
x=6.5
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
elif (c==3):
x=6.25
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
elif(c>3)
x=6.0
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
elif (b>60):
if c==1:
x=7.0
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
elif (c==2):
x=6.5
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
elif (c==3):
x=6.75
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
elif(c>3)
x=6.5
y=a*c*x/100
print (“Sum:” ,a, ”Term”, c , “Age”, b ,
“interest” ,x, “Amount” , y)
10.Write a program by
using user’s choice to
perform the following tasks
by taking suitable variables
(i) Volume of cuboid
(ii)Volume of cylinder
(iii)Volume of cone
Code:
N=(input(“Enter the calculation you want to carry
out”))
if N==”Volume of cuboid “:
a=int(input(“Enter the length”))
b=int(input(“Enter the breadth”))
c=int(input(“Enter the height”))
d=a*b*h
print(“The volume is”, d)
elif(N==”Volume of cylinder”):
a=int(input(“Enter the radius”))
c=int(input(“Enter the height”))
d=3.14*a*a*c
print(“The volume is”, d)
elif (N==”Volume of cone”)
a=int(input(“Enter the radius”))
c=int(input(“Enter the height”))
d=1/3*3.14*a*a*c
print(“The volume is”,d)
else:
print(“Sorry”)