0% found this document useful (0 votes)
17 views14 pages

Practical No 11

The document provides several Python programming exercises, including defining functions with multiple arguments, returning values, and performing tasks such as checking for prime numbers, calculating factorials, and counting uppercase and lowercase letters in a string. It includes example code snippets and their expected outputs. The exercises aim to enhance understanding of user-defined functions in Python.

Uploaded by

sohamastane077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views14 pages

Practical No 11

The document provides several Python programming exercises, including defining functions with multiple arguments, returning values, and performing tasks such as checking for prime numbers, calculating factorials, and counting uppercase and lowercase letters in a string. It includes example code snippets and their expected outputs. The exercises aim to enhance understanding of user-defined functions in Python.

Uploaded by

sohamastane077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

PRACTICAL NO 11

Develop user defined python function for


given problem
1.Function with minimum 2 arguments
2.Function Returning values
1.What is the output of the following program
def myfunc(text,num):
while num>0:
print(text)
num=num-1
myfunc('Hello',4)
Output
Hello
Hello
Hello
Hello
2.What is the output of the following program
num=1
def func():
num=3
print(num)
func()
print(num)
Output
3
1
1.Write a Function that takes a number as a
parameter and check the number is prime or
not.
def primenumber(num):
if num>1:
for i in range(2,num):
if(num%i==0):
prime=False
break
else:
prime=True
if(prime==True):
print(num," is a prime number")
else:
print(num," is not a prime number")
else:
print("number is equal to 1")
primenumber(9)
Output
9 is not a prime number
2.Write a python function to calculate the
factorial of a number. The function accepts
the number as an argument
def fact(num):
f=1
while(num>0):
f=f*num
num=num-1
print(f)
fact(5)
Output
120
3.Write a python function that accepts a
string and calculate the number of upper
case and lower case letters.
def myfunc():
st=input("Enter a string : ")
upper=0
lower=0
for i in st:
if (i.isupper() == True):
upper=upper+1
else:
lower=lower+1
print("Number of upper case letters : ",upper)
print("Number of lower case letters : ",lower)
myfunc()
Output
Enter a string : Amit Patil
Number of upper case letters : 2
Number of lower case letters : 8
End

You might also like