0% found this document useful (0 votes)
12 views

python pdf

Python code
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)
12 views

python pdf

Python code
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/ 1

Bubbel sort

Avg mks
m1 = int(input("Enter the M1 marks: "))
arr = list(map(int, input("Enter numbers separated by spaces: ").split()))
m2 = int(input("Enter the M2 marks: ")) for i in range(len(arr)): Reggular expression
m3 = int(input("Enter the M3 marks: ")) for j in range(len(arr)-i-1):
marks = [m1, m2, m3]
marks.sort(reverse=True) if arr[j] > arr[j+1]: def pattern_recognition_without_regex(text, pattern):
total = marks[0] + marks[1] arr[j], arr[j+1] = arr[j+1], arr[j] if pattern in text:
avg = total / 2 print("Sorted array:", arr)
Upper case lovwer case return True
print("Avg marks:", avg) def count_sentence_details(sentence):
else:
num_words = 0
return False
palindrome num_digits = 0
Smallest and largest num_uppercase = 0
my_list=[1,5,6,76,10] num_lowercase = 0 text = "The quick brown fox jumps over the lazy dog."
def is_palindrome(number): pattern = "fox"
my_list.sort() words = sentence.split()
num_str = str(number) result = pattern_recognition_without_regex(text, pattern)
print("largest number is :",my_list[-1]) num_words = len(words)
return num_str == num_str[::-1]
print("smallest number is :",my_list[0]) def count_digits(number):
for char in sentence: if result:
num_str = str(number)
Ascending if char.isdigit(): print(f"Pattern '{pattern}' found in the text!")
digit_count = {}
a = "ascending" num_digits += 1 else:
for digit in num_str:
d = "descending" elif char.isupper(): print(f"Pattern '{pattern}' not found in the text!")
if digit in digit_count:
numbers = [1,2,8,6,9,14,25,35,85,10] num_uppercase += 1
digit_count[digit] += 1
numbers.sort() elif char.islower():
else:
print(a,":",numbers) num_lowercase += 1
digit_count[digit] = 1
numbers.sort(reverse=True) return digit_count
print(d,":",numbers) return num_words, num_digits, num_uppercase, num_lowercase
num = int(input("Enter a number: "))
sentence = input("Enter a sentence: ")
Binary num_words, num_digits, num_uppercase, num_lowercase =
def binary_search(arr, target): if is_palindrome(num):
count_sentence_details(sentence)
low = 0 print(f"{num} is a palindrome.")
high = len(arr) - 1 else:
print(f"Number of words: {num_words}")
while low <= high: print(f"{num} is not a palindrome.")
print(f"Number of digits: {num_digits}")
mid = (low + high) // 2 print(f"Number of uppercase letters: {num_uppercase}")
digit_occurrences = count_digits(num)
if arr[mid] == target: print(f"Number of lowercase letters: {num_lowercase}")
print("Digit occurrences:")
return mid
for digit, count in digit_occurrences.items():
elif arr[mid] < target:
print(f"Digit {digit}: {count} times")
low = mid + 1
else:
high = mid - 1
return -1

You might also like