python pra10
python pra10
DOP: DOS:-
Practical No 10
1) the number of upper case letters and lower case letters.
Code:-
def count_case_letters(input_string):
upper_case_count = 0
lower_case_count = 0
if char.isupper():
upper_case_count += 1
elif char.islower():
lower_case_count += 1
Output:-
2) Write a Python program to generate a random float where the value is
between 5 and 50 using Python math module.
Code:-
import random
import math
Output:-
3) Write Python program to demonstrate math built-in functions.
Code:-
import math
def demonstrate_math_functions():
print("Math Constants:")
print(f"Pi: {math.pi}")
print()
num = 16
print()
angle = 45
radians = math.radians(angle)
print("Trigonometric Functions:")
print()
print(f"Exponential of 2: {math.exp(2)}")
print()
base = 2
exponent = 3
print()
print("Rounding Functions:")
float_num = 5.7
if __name__ == "__main__":
demonstrate_math_functions()
Output:-
4) Write Python program to demonstrate string built-in functions
Code:-
def demonstrate_string_functions():
print("Original String:")
print(f"'{sample_string}'")
print()
print(f"Length: {len(sample_string)}")
print()
print(f"Uppercase: {sample_string.upper()}")
print(f"Lowercase: {sample_string.lower()}")
print()
print(f"Original: '{sample_string}'")
print(f"Stripped: '{sample_string.strip()}'")
print()
print()
print("5. Replacing Substrings:")
print()
words = another_string.split()
print()
print()
name = "Alice"
age = 30
print(formatted_string)
if __name__ == "__main__":
demonstrate_string_functions()
Output:-