![Python-courses-python-exercises-python-certification](https://1.bp.blogspot.com/-T3BongcoJFo/X4CftQxVL8I/AAAAAAAAB5U/Lf59WgNyhGo2FdogKqxv0PIy_Ef7XDPdgCLcBGAsYHQ/s0/my-python-courses-python-exercises-with-solutions.png)
Exercise 71 **
Write a Python program which determines the minimum digit within a given string s. Example if s = "Python3.7 is more power than Python2.7" , the algorithm must returns 2. We assume that the string s does not contain any negative number.
Solution
def minimumDigit(s):
# creating and initializing the list of digits
listDigits = []
for x in s:
if x.isdigit():
x = int(x)
listDigits.append(x)
# initializing the minimum of digits
minDigit = listDigits[0]
# iterate over all list elements
for n in listDigits:
if minDigit > n:
minDigit = n
return minDigit
# Example:
s = "Python3.7 is more power than Python2.7"
print("The minimum digit within s is : ", minimumDigit(s))
# The output is : The minimum digit within s is : 2
Younes Derfoufi
my-courses.net
my-courses.net