0% found this document useful (0 votes)
9 views20 pages

Index

Uploaded by

manish.anil8b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

Index

Uploaded by

manish.anil8b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

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

1. Generate the following


nested pattern using
nested loop:
Pattern 1 Pattern 2 Pattern 3
* 12345 A
** 1234 AB
*** 123 ABC
**** 12 ABCD
***** 1 ABCDE

 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

2.Write the program to


input the value of x and n
and print the sum of the
following series:
1. 1+x2+x3+x4……+an
Code:
x=int (input ("Enter value of x"))
n=int (input ("Enter the value of n"))
s=0
for a in range (n+1):
term=(x**a)
s+=term

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

4.x+x2/2! – x3/3! + x4/4! – x5/5!


+x6/6
Code:
x =int (input ("Enter the value of x:"))
n=int (input ("Enter the power (n):"))
s=x
sign=+1
for a in range (2, n+1):
f=1
for I in range (1, a+1):
f*=1
term=((x**a) *sign)/f
s+=term
sign*=-1
print ("Sum of first", n," terms:", s)
Output:
Enter the value of x:4
Enter the power (n):5
Sum of first 5 terms: -812.0

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

4.To check whether a


number is prime or
composite:
Code:
N=int (input (“Enter any number”)
if n>1:
for I in range (2, n):
if (N % I ==0):
print (N, is not a prime but a
composite number)
else:
print (N, is a prime number)
Output:
Enter any number;24
24 is not a prime but a composite number

5.Display the Fibonacci


series
Code:
n=int (input (“How many terms”))
n1, n2=0,1
count=0
if n<=0
print (“Please enter a valid number”)
elf n==1
print (“Fibonacci series up to n)
while count<n:
print(n1)
nth=n1+n2
n1=n2
n2=nth
count +=1

Output:
How many terms? 8
Fibonacci series up to 8
0
1
1
a
3
5
8
13

6.Compute the greatest


common divider and least
common multiple of 2
integers
A=int (input (“Enter any number”))
B= int (input (“Enter any number “))
for I in range (1, A+1):
if a % I==0 and b % I==0
print (“The greatest common divisor is “, I)
gcd=I
lcm=(A*B)/I
print (“The lcm is”, lcm)
else:
print(i,”not the greatest common divisor”,i)

Output:
Enter any number 12
Enter any number 18
The greatest common divisor, 6
The lcm is 36

7.A number is said to be a


perfect square if its square
root is an integer number.
Write a python code to
input two unequal positive
numbers and check whether
they are perfect square
numbers or not. If the user
enters a negative number,
then appropriate message
should be shown.
Code:

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

8.Enter three number and


check if they are equal if
they are unequal give
appropriate output.
Code:
X=int(input(“Enter any number1”))
Y=int(input(“Enter any number2”))
Z=int(input(“Enter any number 3”))
if X==Y==Z :
print(“The three numbers” ,X ,Y ,Z ,”are equal”)
else:
print(“The three numbers”, X, Y, Z, “are
unequal”)

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”)

Efforts by: Manish. A. Kadam Class; XI SCI


B Roll no;17

You might also like