Skip to content

Write a Python program to find the second largest digit present in a string entered by the user.

ASSIGNMENT

Q.5

Q.5 Write a Python program to find the second largest digit present in a string entered by the user. 

string = input("Enter a string: ") digits = [] for ch in string: if ch.isdigit(): digits.append(int(ch)) digits = list(set(digits)) if len(digits) < 2: print("Second largest digit does not exist.") else: digits.sort(reverse=True) print("Second largest digit is:", digits[1])