Jul-07-2019, 09:08 PM
I've written a program that inputs three integers and calls functions to determine the smallest and the largest of the three. But sometimes my program gives the wrong answer. I have written this program in C# the same way and there is no bugs.
In this Python version if I enter the integers 1, 3, and 6 my program reports that the smallest is 1 and the largest is 3.
Here is what I've currently got:
In this Python version if I enter the integers 1, 3, and 6 my program reports that the smallest is 1 and the largest is 3.
Here is what I've currently got:
def smallest(a, b, c):
smallest = a
if b < smallest:
smallest = b
elif c < smallest:
smallest = c
return smallest
def largest(a, b, c):
largest = a
if b > largest:
largest = b
elif c > largest:
largest = c
return largest
x = int(input("Enter first number:"))
y = int(input("Enter second number:"))
z = int(input("Enter third number:"))
print()
smallest_integer = smallest(x, y, z)
largest_integer = largest(x, y, z)
print("The smallest is", smallest_integer)
print("The largest is", largest_integer)
