Question

In: Computer Science

This phyton program takes in three integer parameters and displays them in ascending order. You can...

This phyton program takes in three integer parameters and displays them in ascending order. You can assume that the numbers entered are integers. You CAN'T use lists, min(), max(), or the sort utility.  The point is to use if tests. 

sortThreeIntegers( 39, 2, 5 ) should display:
The numbers in order are: 2 5 39

sortThreeIntegers( 14, -12, -1000 ) should display:
The numbers in order are: -1000 -12 14
def sortThreeIntegers( x, y, z ):
   < your code goes here >

Solutions

Expert Solution

def sortThreeIntegers(a,b,c):
    print("The numbers in order are: ",end="")
    if (a <= b and a <= c):
        print(a, end=" ")
        if (b <= c):
            print(b, end=" ")
            print(c, end="")
        else:
            print(c, end=" ")
            print(b, end="")
    elif (b <= a and b <= c):
        print(b, end=" ")
        if (a <= c):
            print(a, end=" ")
            print(c, end="")
        else:
            print(c, end=" ")
            print(a, end="")
    else:
        print(c, end=" ")
        if (a <= b):
            print(a, end=" ")
            print(b, end="")
        else:
            print(b, end=" ")
            print(a, end="")
    print()
    

# Testing
sortThreeIntegers(39,2,5)
sortThreeIntegers(14,-12,-1000)


Related Solutions

Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM] =...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include <iostream> using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM]...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them...
Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include <iostream> using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67}; int arrB[NUM]...
Write a program that will ask the user for three words (strings). Re-arranges them in ascending...
Write a program that will ask the user for three words (strings). Re-arranges them in ascending order by using a function (it should return void). Global variables are forbidden. Hint: You don't need to exchange the values among variables. You can just print them in the correct order. (C++ Please) Example of Output: Word 1: apple Word 2: orange Word 3: strawberry -------- orange apple strawberry
Write a function called fillList that takes three parameters, an integer array, input file, and size....
Write a function called fillList that takes three parameters, an integer array, input file, and size. The function should fill the integer array with randomly generated values between two numbers lowLim and highLim read from the input file. in C++
Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer called removeItem.
Java programming:Write a method, remove, that takes three parameters: an array of integers, the length of the array, and an integer called removeItem. The method should find and delete the first occurrence of removeItem in the array. If the value does not exist or the array is empty, output an appropriate message. (Note that after deleting the element, the array size is reduced by 1.) You may assume that the array is unsorted.Now re-do this exercise and name it ExInsertionSort....
in C++ Given two integer arrays sorted in the ascending order, code the function SortArrays to...
in C++ Given two integer arrays sorted in the ascending order, code the function SortArrays to merge them into one array in the descending order. You need to make sure if the values in the arrays are changed, it will still work. (25 points) #include <iostream> using namespace std; void SortArrays (int a[], int b[], int c[], int size); void printArray(int m[], int length); const int NUM = 5; int main() { int arrA[NUM] = {-2, 31, 43, 55, 67};...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from an infinite series of the form: π / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ... However, there is another novel approach to calculate π. Imagine that you have a dartboard that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from an infinite series of the form: π / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ... However, there is another novel approach to calculate π. Imagine that you have a dartboard that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT