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

shreepad

Py cheets
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

shreepad

Py cheets
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

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

num = int(input("Enter a number: "))

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")

7 sentence and digit

def count_sentence_details(sentence):
num_words = 0
num_digits = 0
num_uppercase = 0
num_lowercase = 0
words = sentence.split()
num_words = len(words)

for char in sentence:


if char.isdigit():
num_digits += 1
elif char.isupper():
num_uppercase += 1
elif char.islower():
num_lowercase += 1

return num_words, num_digits, num_uppercase, num_lowercase

sentence = input("Enter a sentence: ")


num_words, num_digits, num_uppercase, num_lowercase =
count_sentence_details(sentence)

print(f"Number of words: {num_words}")


print(f"Number of digits: {num_digits}")
print(f"Number of uppercase letters: {num_uppercase}")
print(f"Number of lowercase letters: {num_lowercase}")

8.regular

def pattern_recognition_without_regex(text, pattern):


if pattern in text:
return True
else:
return False

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!")

You might also like