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

Practical No 11

The document contains three Python exercises: one for checking if a number is prime, another for calculating the factorial of a non-negative integer, and a third for counting uppercase and lowercase letters in a string. Each exercise includes a function definition and a sample input/output. The code snippets demonstrate basic programming concepts and functions in Python.

Uploaded by

samarthn001
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)
23 views3 pages

Practical No 11

The document contains three Python exercises: one for checking if a number is prime, another for calculating the factorial of a non-negative integer, and a third for counting uppercase and lowercase letters in a string. Each exercise includes a function definition and a sample input/output. The code snippets demonstrate basic programming concepts and functions in Python.

Uploaded by

samarthn001
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

Practical No 11

X. Exercise

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

def test_prime(n):
if(n == 1):
return False
elif(n == 2):
return True;
else:
for x in range(2,n):
if(n % x==0):
return False
return True
print(test_prime(int(input("Enter number to check - "))))

Output –
Que 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 factorial(n):
if n == 0:
return 1
else:
return n*factorial(n-1)
n = int(input("Input a number to compute the factorial = "))
print(factorial(n))

Output –

Que 3 - Write a Python function that accepts a string and calculate the number of upper
case letters and lower case letters.

def string_test(s):
d = {"UPPER_CASE":0,"LOWER_CASE":0}
for c in s:
if c.isupper():
d["UPPER_CASE"]+=1
elif c.islower():
d["LOWER_CASE"]+=1
else:
pass
print("Original String :- ",s)
print("No. of Upper case Chars :- ",d["UPPER_CASE"])
print("No. of Lower case Chars :- ",d["LOWER_CASE"])
string_test("Shantanu Anant Gaikwad")
Output –

You might also like