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

Dhruvesh Patel

Hahjs

Uploaded by

r8889127
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)
9 views3 pages

Dhruvesh Patel

Hahjs

Uploaded by

r8889127
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/ 3

1.

Write a program isprime(n) if return 1 then


prime number otherwise composite number.
Source code:

def prime(n):
count = 0
for i in range(1,n+1):
if n % i == 0:
count = count + 1
if count == 2:
return 1
else:
return 0
n = int(input("enter a number: "))
D = prime(n)
if D == 1:
print(n,"is prime number")
else:
print(n,"is composite number")

output:

enter a number: 2

2 is prime number

2.palindrome string using function


Source code:

def pal(str):
if (str == str[::-1]):
print("Yes, it is Palindrome")
else:
print(" it is not Palindrome")

str = input("Enter the string to check palindrome : ")


pal(str)
output:

Enter the string to check palindrome : naman

Yes, it is Palindrome

3.ncr and npr using recursive function for


factorial calculation
Source code:

def fact(n):
if n == 1 or n == 0:
return 1
else:
return(n * fact(n-1))

def fact(r):
if r == 1 or r == 0:
return 1
else:
return(r * fact(r-1))

def fact(dif): #here dif is (n-r)


if (dif) == 1 or (dif) == 0:
return 1
else:
return((dif) * fact(dif-1))

n = int(input("enter n : "))
r = int(input("enter r : "))
D = fact(n)
K = fact(r)
dif = int(n-r)
F = fact(dif) #here dif is (n-r)
npr = (D/F)
print("npr is =", npr)
ncr = (npr/K)
print("ncr is =", ncr)
output:

enter n : 8

enter r : 4

npr is = 1680.0

ncr is = 70.0

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy