feat: completed exercise 15
This commit is contained in:
+15
-1
@@ -1,4 +1,18 @@
|
|||||||
"""
|
"""
|
||||||
Write a program to find the largest and smallest digit within a given integer (e.g., in 75869, the largest is 9 and
|
Write a program to find the largest and smallest digit within a given integer (e.g., in 75869, the largest is 9 and
|
||||||
the smallest is 5).
|
the smallest is 5).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
number = 75869
|
||||||
|
largest = number % 10
|
||||||
|
smallest = number % 10
|
||||||
|
|
||||||
|
while number > 0:
|
||||||
|
digit = number % 10
|
||||||
|
if digit > largest:
|
||||||
|
largest = digit
|
||||||
|
if digit < smallest:
|
||||||
|
smallest = digit
|
||||||
|
number = number // 10
|
||||||
|
|
||||||
|
print(largest, smallest)
|
||||||
Reference in New Issue
Block a user