The document provides a practical guide for writing Python programs that demonstrate built-in math and string functions. It explains string formatting using the '%' operator, the usage of the title() and capitalize() methods, and the significance of the strip() method. Additionally, it includes examples of functions to count uppercase and lowercase letters in a string and to generate a random float between 5 and 50 using the math module.
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 ratings0% found this document useful (0 votes)
8 views13 pages
Practical No 10
The document provides a practical guide for writing Python programs that demonstrate built-in math and string functions. It explains string formatting using the '%' operator, the usage of the title() and capitalize() methods, and the significance of the strip() method. Additionally, it includes examples of functions to count uppercase and lowercase letters in a string and to generate a random float between 5 and 50 using the math module.
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/ 13
PRACTICAL NO 10
Write Python program to
demonstrate math built in function and string built in function 1. Describe about string formatting operator with example. The string format operator %. is unique to strings and makes up for the pack of having functions from C's printf() family. Ex print ("My name is %s and weight is %d kg!" % ('Zara', 21)) Output My name is Zara and weight is 21 kg! List of complete set of symbols which can be used along with % 2. Give the Syntax and example of title() and capitalize() method I. title() This method returns a copy of the string in which first characters of all the words are capitalized. Syntax str.title(); Ex str = "this is String example" print (str.title()) Output This Is String Example II. capitalize() Python String capitalize() method returns a copy of the string with only its first character capitalized. Syntax str.capitalize() Ex. str = "this is String example" print (str.capitalize()) Output This is string example 3. Give the syntax and significance of strip(). Python string method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters). Syntax str.strip([chars]); Ex str = "0000000this is string example0000000"; print (str.strip( '0') ) Output this is string example 1.Write python function that accepts a string and calculate the number of upper case and lower case letters. def countupanlow(): s=input("Enter the string:") up=0 lo=0 for i in range(0,len(s)): if(s[i].isupper()!=0): up=up+1 else: lo=lo+1 print("UpperCase letters are",up," and LowerCase are",lo) countupanlow() Output Enter the string:Amit Patil UpperCase letters are 2 and LowerCase are 8 2.Writ e a python program to generate a random float where the value is between 5 and 50 using python math module import random print("Random number is",random.uniform(5.1,50.1)) Output Random number is 38.84405799440543 End