0% found this document useful (0 votes)
6 views2 pages

PR 11

The document contains three Python functions: one to check if a number is prime, another to calculate the factorial of a non-negative integer, and a third to count the number of uppercase and lowercase letters in a string. Each function includes code snippets and prompts for user input. The document also includes sample outputs for each function.

Uploaded by

trushnaanantwal
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)
6 views2 pages

PR 11

The document contains three Python functions: one to check if a number is prime, another to calculate the factorial of a non-negative integer, and a third to count the number of uppercase and lowercase letters in a string. Each function includes code snippets and prompts for user input. The document also includes sample outputs for each function.

Uploaded by

trushnaanantwal
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/ 2

Practical No:11

1. Write a Python function that takes a number as a parameter


and check the number is prime or not.

Code:
def prime(n):
if n>1:
for i in range(2,n):
break
if(n%i)==0:
print(n,"number is not prime")
else:
print(n,"number is prime")
a=int(input("Enter number:-"))
prime(a)

Output:

2. Write a Python function to calculate the factorial of a number


(a non-negative integer). The function accepts the number as an
argument.

Code:
def fact(num):
fact=1
if(num<0):
print("Factorial does not exist for negative number")
elif(num==0):
print("Factorial of 0 is 1")
else:
for i in range(1,num+1):
fact=fact*i
print("factorial of number:",fact)
n=int(input("Enter a number="))
fact(n)
Output:

3. Write a Python function that accepts a string and calculate the


number of upper case letters and lower case letters.

def fun(str):
lower=0
upper=0
for i in range(len(str)):
if(str[i]>='A' and str[i]<='Z'):
upper+=1
elif(str[i]>='a' and str[i]<='z'):
lower+=1
else:
print(" ")
return(upper,lower)
str="NMPI computer dept"
print("College name=",str)
u,l=fun(str)
print("Uppercase character=",u)
print("Lowercase character=",l)

Output:

You might also like