0% found this document useful (0 votes)
15 views

Python Programs for Class IX

Uploaded by

jnprasad95
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)
15 views

Python Programs for Class IX

Uploaded by

jnprasad95
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/ 6

Q.

1 Write a Python Program to calculate Factorial of a given Number by using for


loop.
N = int ( input( “ Enter any number = “))
F=1
for I in range ( 1, N+1) :
F=F*I
print ( “ The Factorial of a given number “,N,” is = “,F)

Q.2 Program to calculate factorial of a given number by using while loop

n=int(input(" Enter the range value = "))


f=1
i=1
while i<=n:
f=i*f
i=i+1
print("==============================")
print(" Factorial of ",n," is = ",f)
print("==============================")

Q.3 Write a Python Program to generate all even numbers for a given range and find
their sum by using for loop.
N=int(input( “ Enter the range value = “)
s=0
I=0
print(“\n The Even Numbers are as ….. \n”)
for I in range (N+1) :
print (I, end= “ “)
s=s+I
I = I +2
print(“ Sum of all the even numbers are = “,s)
Output
Enter the range value = 15
The Even Numbers are as …..
0 2 4 6 8 10 12 14
Sum of all even numbers are = 56
Q.4 Program to generate all Even Numbers for a given range by using while loop

n=int(input(" Enter the range value = "))


s=0
print(" Even numbers are as ....... ")
print("==============================")
i=0
while i<=n:
print("\t",i)
s=s+i
i=i+2
print("==============================")
print("SUM of all Even Numbers are = ",s)

Q.5 Write a Python Program to generate all Odd numbers for a given range and find
their sum .
# program to generate Odd numbers
N=int(input( “ Enter the range value = “)
s=0
I=1
print(“\n The Even Numbers are as ….. \n”)
for I in range (N+1) :
print (I, end= “ “)
s=s+I
I = I +2
print(“ Sum of all the Odd numbers are = “,s)

Output

Enter the range value = 10


The Odd Numbers are as …..
13579
Sum = 25
Q.6 Write a Python Program to generate all Natural numbers for a given range and
find their sum .
# program to generate Odd numbers
N=int(input( “ Enter the range value = “)
s=0
I=1
print(“\n The Natural Numbers are as ….. \n”)
for I in range (N+1) :
print (I, end= “ “)
s=s+I
I = I +1
print(“ Sum of all the Natural numbers are = “,s)

Output

Enter the range value = 10


The Natural Numbers are as …..
1 2 3 4 5 6 7 8 9 10
Sum = 55

Q.7 Write a Python Program to generate a table of any number in Tabular form.
17 x 1 = 17
17 x 2 = 34

N=int(input(“ Enter the number whose table you want = “))


M=int(input(“ Enter the max limit up to which table you want “))
P=1
print(“The table of “,N , “ is as……\n”)
for I in range(M+1):
P = P*I
print( N, “X”, I, “ = “, P)
print(“\n ……………………………………………..”)
Q.8 Write a Python Program to generate all Factorial numbers for a given range.

N=int(input(“ Enter the range value = “)


F=1
print(“\n The Factorial series is as ……\n”)
for I in range (N+1):
F=1
for J in range ( I+1):
F=F*J
print(“ Factorial of “, I , “ is = “,F)
print(“\n ……………………………………..\n”)

Q.9 Write a Python Program to find sum of all the digits of given number .
N=3456
S =18

n=int(input(" Enter any number of any digit = "))


s=0
while n >0 :
iq=n//10
ir=n-iq*10
s=s+ir
n=iq
print(" The sum of all the digits is = ",s)

Output
N = 456
S = 15

Q. 10 Write a Python Program to Calculate Simple Interest and Compound Interest


for given P,T and R value.

import math
P = int(input(“ Enter the value for Principle Amt = “))
R =int(input(“ Enter the value for rate = “))
T = int (input(“ Enter the value for time =”))
SI = (P*R*T)//100
print(“ The simple interest is = “, SI)

A= P*(pow(1+R/100),T)
CI= A-P
print(“ The Compound interest is = “, CI)
Q . 11 Write a Python Program to calculate area of a right angled triangle .

B = int( input ( “ Enter the value of Base = “))


H= int( input ( “Enter the value of Height =”))
A= 0.5 * ( B*H)
print ( “ The area of Triangle is = “, A)

Q .12 Write a Python Program to check whether given number is Even or Odd.

N = int ( input ( “ Enter the Number = “))


if ( N % 2 == 0)
print (“ The given Number “, N , “ is an Even Number “)
else
print (“ The given Number “, N , “ is an Odd Number “)

Q.13 program to generate Fibonacci Series

n=int(input( " Enter any range value of your choice = "))


n1=0
n2=1
i=2
print(" Fibonacci Series is as ........")
print("\t",n1)
print("\t",n2)
while i < n:
n3=n1+n2
print("\t",n3)
n1=n2
n2=n3
i=i+1
Q.14 Program to check whether string contains digit or/not.

str = input(" Enter a string " )


test = False
str2=""
dig="0123456789"
for ch in str :
if ch in dig :
str2=str2+ch
test = True

print(" The digit in string is = ", str2)

if test == False :
print (" The string doesn’t contains digit .")

Q.15 Program to check whether given number is prime or /not

n=int(input(" Enter any number to check Prime = "))


d=0
for i in range (1, n+1):
if(n%i==0):
d=d+1
if(d<=2):
print(" Given number ", n, " is a Prime Number")
else:
print(" Given number ", n, " is not a Prime Number")

Q.16 Program to generate all prime number for a given range .

n=int(input(" Enter the range value = "))


print(" Prime numbers are as = .......")

for i in range (1, n+1):


d=0
for j in range (1,i+1):
if(i%j==0):
d=d+1
if(d<=2):
print(i)

You might also like