0% found this document useful (0 votes)
264 views4 pages

PWP Practical 11 PDF

The document provides guidelines for writing practical write-ups and contains 3 examples of python functions: 1. A function that prints a text a given number of times. 2. A function that checks if a number is prime or not. 3. A function that calculates the factorial of a non-negative integer.

Uploaded by

pruthviraj patil
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)
264 views4 pages

PWP Practical 11 PDF

The document provides guidelines for writing practical write-ups and contains 3 examples of python functions: 1. A function that prints a text a given number of times. 2. A function that checks if a number is prime or not. 3. A function that calculates the factorial of a non-negative integer.

Uploaded by

pruthviraj patil
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/ 4

Practical No.

11

GUIDELINES FOR WRITING THE PRACTICAL WRITEUP

1. Use ruled file pages for write-up of practical contents.


2. You can use both side ruled pages for the same.
3. Start each practical (experiment) write-up on new page.
4. Maintain all these practical work in a file as it will be considered for
TW (continuous assessment) of the course PWP.
5. Write question answers given and take print out of only programs or
can write it on assignment pages.
6. Complete the practical write-up in time. Don’t keep it pending.

Practical No. 11: Develop user defined python function for given problem.

1. What is the output of the following program?

def myfunc(text,num):
while num>0:
print(text)
num=num-1
myfunc('Hello',4)

Ans:

Hello
Hello
Hello
Hello
Practical No. 11

1. Write a python function that takes anumber as a parameter


and check the number is prime or not

def prime(n):
i=2
c=0
while(i<n):
if(n%i==0):
c=c+1
i=i+1

if(c==0):
print(n," is Prime Number")
else:
print(n," is Non-Prime Number")
i=int(input("Enter any number: "))
prime(i)

Output:
>>> %Run exp11_1.py

Enter any number: 5


5 is Prime Number

>>> %Run exp11_1.py

Enter any number: 6


6 is Non-Prime Number
Practical No. 11

2. Write a python function to calculate the factorial of a


number( a non negative integer). The function should
accept the number as an argument
def factorial(n):

if(n>0):

fact=1

i=1

while(i<=n):

fact=fact*i

i=i+1

print("Factorial of ",n," is ",fact)

else:

print("Factorial of negative number can't be calculated")

exit

i=int(input("Enter any number: "))

factorial(i)

Output:
>>> %Run exp11_2.py

Enter any number: 5


Factorial of 5 is 120

>>> %Run exp11_2.py

Enter any number: -5


Factorial of negative number can't be calculated
Practical No. 11

3. Write a python function that accepts a string and


calculate the number of upper case letters and lower case
letters

def upperlower(s):
lower=0
upper=0
for i in s:
if(i.islower()):
lower=lower+1
if(i.isupper()):
upper=upper+1
print("Lower case characters :",lower)
print("Upper case characters :",upper)
str1=str(input("Enter any string :"))
upperlower(str1)

Output:

>>> %Run exp11_3.py

Enter any string :This is Python


Lower case characters : 10
Upper case characters : 2

You might also like