इस ट्यूटोरियल में, हम एक प्रोग्राम लिखने जा रहे हैं जो तीन अंकों से अधिकतम राशि का पता लगाता है। हमारे पास तीन संख्याएँ होंगी, और हमारा लक्ष्य उन तीन संख्याओं में से अधिकतम संख्या ज्ञात करना है।
आइए बेहतर समझ के लिए कुछ नमूना परीक्षण मामलों को देखें।
Input: a, b, c = 2, 34, 4 Output: 34
Input: a, b, c = 25, 3, 12 Output: 25
Input: a, b, c = 5, 5, 5 Output: 5
तीन संख्याओं में से अधिकतम संख्या जानने के लिए नीचे दिए गए चरणों का पालन करें।
एल्गोरिदम
1. Initialise three numbers a, b, c. 2. If a is higher than b and c then, print a. 3. Else if b is greater than c and a then, print b. 4. Else if c is greater than a and b then, print c. 5. Else print any number.
आइए उपरोक्त एल्गोरिथम के लिए कोड देखें।
उदाहरण
## initializing three numbers
a, b, c = 2, 34, 4
## writing conditions to find out max number
## condition for a
if a > b and a > c:
## printing a
print(f"Maximum is {a}")
## condition for b
elif b > c and b > a:
## printing b
print(f"Maximum is {b}")
## condition for c
elif c > a and c > b:
## printing
print(f"Maximum is {c}")
## equality case
else:
## printing any number among three
print(a) आउटपुट
यदि आप उपरोक्त प्रोग्राम चलाते हैं, तो आपको निम्न आउटपुट मिलेगा।
Maximum is 34
आइए अलग-अलग टेस्ट केस के लिए एक बार फिर कोड निष्पादित करें
उदाहरण
## initializing three numbers
a, b, c = 5, 5, 5
## writing conditions to find out max number
## condition for a
if a > b and a > c:
## printing a
print(f"Maximum is {a}")
## condition for b
elif b > c and b > a:
## printing b
print(f"Maximum is {b}")
## condition for c
elif c > a and c > b:
## printing
print(f"Maximum is {c}")
## equality case
else:
## printing any number among three
print(f"Maximum is {a}") आउटपुट
यदि आप उपरोक्त प्रोग्राम चलाते हैं, तो आपको निम्न आउटपुट मिलेगा।
Maximum is 5
निष्कर्ष
यदि आपको ट्यूटोरियल के बारे में कोई संदेह है, तो उनका टिप्पणी अनुभाग में उल्लेख करें।