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

Practical 11 Py

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 is defined with appropriate logic and includes user input for testing. The examples provided demonstrate the functionality of each function.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Practical 11 Py

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 is defined with appropriate logic and includes user input for testing. The examples provided demonstrate the functionality of each function.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL 11

1.Write a Python function that takes a number as a parameter and check the number is
prime or not.

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)

2. Write a Python function to calculate the factorial of a number (a non negative integer).
The function accepts the number as an argument.
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)
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)

You might also like