Computer
Python programs
Mrs.Nashra Javed
SHRUTI
12
1|Page
● P yth o n P ro g ra m m in g Q u e stio n s:
1.Program to illustrate the concepts of different
types of conditional statement.
x = 10
if x > 0 :
p rin t("P o sitive ")
e lif x = = 0 :
p rin t("Z e ro ")
e lse :
p rin t("N e g a tive ")
2|Page
2. Program to illustrate the concepts of different
types of iterative and transfer statements:
Python.
fo r i in ra ng e (5 ):
if i = = 3 :
c o n tin ue
p rin t(i)
3|Page
3. Program to calculate factorial of a given number:
d e f fa cto ria l(n):
if n = = 0 :
retu rn 1
e lse :
retu rn n * fa cto ria l(n-1 )
n um = 5
p rint("Fa c to ria l o f", nu m , "is", fac to rial(n u m ))
4|Page
4. Program to display Fibonacci series:
d e f fib o n a cc i(n ):
fib _serie s = [0 , 1 ]
fo r i in ran g e (2 , n):
fib _se rie s.a p p e nd (fib _se ries[-1 ] +
fib _se rie s[-2 ])
re turn fib _serie s
n = 10
p rint("Fib o na c ci serie s u p to ", n, "term s:",
fib o n ac c i(n ))
5|Page
5. Program to check whether a number is
Palindrome number or not:
d e f is_p a lind ro m e (nu m ):
re turn str(nu m ) = = str(n u m )[::-1 ]
n um = 1 2 1
if is_p a lin d ro m e (n um ):
p rin t(n um , "is a p a lin d ro m e n um b e r")
e lse :
p rin t(n um , "is no t a p alin d ro m e n u m b e r")
6|Page
6. Program to check whether a number is
Armstrong number or not:
d e f is_arm stro n g (n um ):
su m = 0
te m p = nu m
w h ile te m p > 0 :
d ig it = te m p % 1 0
sum + = d ig it ** 3
tem p //= 1 0
re turn n u m == su m
n um = 1 5 3
if is_a rm stro ng (n u m ):
p rin t(n um , "is an A rm stro n g nu m b e r")
e lse :
p rin t(n um , "is no t a n A rm stro ng n um b e r")
7|Page
7. Program to check whether a number is prime or
not:
d e f is_p rim e (n um ):
if n um < = 1 :
retu rn Fa lse
fo r i in ran g e (2 , in t(n u m **0 .5 ) + 1 ):
if nu m % i = = 0 :
re turn F alse
re turn T ru e
n um = 1 7
if is_p rim e (nu m ):
p rin t(n um , "is a p rim e n u m b e r")
e lse :
p rin t(n um )
8|Page
8. Program to remove all Odd numbers from a
given list:
d e f re m o ve _o d d _n um b e rs(lst):
re tu rn [n u m fo r n um in lst if nu m % 2 = = 0 ]
n um b e rs = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 1 0 ]
p rint("List a fte r re m o ving o d d n um b e rs:",
re m o v e_o d d _nu m b e rs(n um b e rs))
9|Page
9. Program to remove vowels from a string:
d e f re m o ve _v o w els(string ):
v o w els = "ae io u A E IO U "
re turn ''.jo in (ch a r fo r c h ar in string if c h ar no t in
vo w e ls)
te xt = "H e llo W o rld "
p rint("S trin g after rem o vin g vo w e ls:",
re m o v e_vo w e ls(te xt))
10 | P a g e
10. Program to check whether the string is
palindrome or not:
d e f is_p a lind ro m e _strin g (string ):
re turn string = = strin g [::-1 ]
te xt = "ra d a r"
if is_p a lin d ro m e _strin g (te xt):
p rin t(te xt, "is a p a lin d ro m e strin g ")
e lse :
p rin t(te xt, "is no t a p alin d ro m e string ")
11 | P a g e
THANK YOU.
12 | P a g e