shreepad
shreepad
Develop a python program to find the better of two test average marks out of
three test's marks accepted from the user.
m1 = int(input("Enter the M1 marks: "))
m2 = int(input("Enter the M2 marks: "))
m3 = int(input("Enter the M3 marks: "))
marks = [m1, m2, m3]
marks.sort(reverse=True)
total = marks[0] + marks[1]
avg = total / 2
print("Avg marks:", avg)
2. Develop a python program to find the smallest and largest number in a list
my_list=[1,5,6,76,10]
my_list.sort()
print("largest number is :",my_list[-1])
print("smallest number is :",my_list[0])
3.Develop a python program to arrange the numbers in ascending and descending order
a = "ascending"
d = "descending"
numbers = [1,2,8,6,9,14,25,35,68,99,100,75,85,10]
numbers.sort()
print(a,":",numbers)
numbers.sort(reverse=True)
print(d,":",numbers)
4 binary
def binary_search(arr, target):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
5 bubble
arr = list(map(int, input("Enter numbers separated by spaces: ").split()))
for i in range(len(arr)):
for j in range(len(arr)-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
print("Sorted array:", arr)
6 palindrome
def is_palindrome(number):
num_str = str(number)
return num_str == num_str[::-1]
def count_digits(number):
num_str = str(number)
digit_count = {}
for digit in num_str:
if digit in digit_count:
digit_count[digit] += 1
else:
digit_count[digit] = 1
return digit_count
if is_palindrome(num):
print(f"{num} is a palindrome.")
else:
print(f"{num} is not a palindrome.")
digit_occurrences = count_digits(num)
print("Digit occurrences:")
for digit, count in digit_occurrences.items():
print(f"Digit {digit}: {count} times")
def count_sentence_details(sentence):
num_words = 0
num_digits = 0
num_uppercase = 0
num_lowercase = 0
words = sentence.split()
num_words = len(words)
8.regular
text = "The quick brown fox jumps over the lazy dog."
pattern = "fox"
result = pattern_recognition_without_regex(text, pattern)
if result:
print(f"Pattern '{pattern}' found in the text!")
else:
print(f"Pattern '{pattern}' not found in the text!")