Python program to sort three integers without using conditional statements and loops

Publié le: 03 avril 2024
sur la chaîne: Py Code Labs
200
23

Python: Sort three integers without using conditional statements and loops
Write a Python program to sort three integers without using conditional statements and loops.

Python Code:

Prompt the user to input three integers and convert them to variables x, y, and z.
x = int(input("Input first number: "))
y = int(input("Input second number: "))
z = int(input("Input third number: "))

Find the minimum value among x, y, and z and store it in variable a1.
a1 = min(x, y, z)

Find the maximum value among x, y, and z and store it in variable a3.
a3 = max(x, y, z)

Calculate the middle value (not the minimum or maximum) by subtracting a1 and a3 from the sum of x, y, and z.
a2 = (x + y + z) - a1 - a3

Print the numbers in sorted order (a1, a2, a3).
print("Numbers in sorted order: ", a1, a2, a3)


Output:

Input first number: 50
Input second number: 80
Input third number: 10
Numbers in sorted order: 10 50 80


#python #ballpython #ballpythonsofinstagram #ballpythons #royalpython #pythonsofinstagram #pythons #pythonregius #ballpythonmorphs #montypython #ballpythonsofig #ballpythonbreeder #pythonprogramming #reticulatedpython #ballpythonmorph #pythonbag #carpetpython #burmesepython #greentreepython #pythoncode #pythonskin #royalpythonsofinstagram #royalpythons #pythonleather #ballpythonbreeding #pythonsofig #python3 #pastelballpython #ballpythonlove #bananaballpython #bloodpython #pythonbracelet #montypythonandtheholygrail #ballpythonofinstagram #gelangpython #babyballpython #piedballpython #ballpythonmorphsofinstagram #pythonbags #pythonshoes #pycodelabs


Sur cette page du site, vous pouvez voir la vidéo en ligne Python program to sort three integers without using conditional statements and loops durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Py Code Labs 03 avril 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 200 fois et il a aimé 23 téléspectateurs. Bon visionnage!