Decision Based Processing in Python in Hindi – Decision Based Processing Kya Hai?
Table of Contents
1. Introduction to Decision Based Processing in Hindi – Decision Based Processing Kya Hai?
2. Decision Making in Algorithms in Hindi – Algorithm में Decision कैसे लिया जाता है?
3. Characteristics of Decision Based Processing in Hindi – इसकी विशेषताएं
4. Decision Symbols in Flowcharts in Hindi – Flowchart में Decision Symbol
5. Conditional Statements in Hindi – Python के Conditional Statements
6. Test Whether a Number is Prime in Hindi – Prime Number Check करना
7. Find Largest Number in an Array in Python in Hindi – Array में सबसे बड़ी Number ढूंढना
Introduction to Decision Based Processing in Hindi – Decision Based Processing Kya Hai?
Sequential Processing में तो हर statement एक fixed order में चलता है, लेकिन असल जिंदगी की ज्यादातर problems में सिर्फ एक सीधा रास्ता काफी नहीं होता, वहां program को यह भी decide करना पड़ता है कि किसी condition के आधार पर कौन सा रास्ता चुनना है, इसी concept को Decision Based Processing कहा जाता है।
Simple भाषा में कहें तो Decision Based Processing एक ऐसी technique है जिसमें program किसी condition को check करता है, और उस condition के True या False होने के हिसाब से अलग-अलग statements execute करता है।
जैसे real life में आप सोचते हैं – "अगर बारिश हो रही है तो छाता ले लूंगा, वरना नहीं", ठीक उसी तरह Python program भी सोचता है – "अगर condition true है तो यह block चलाओ, वरना दूसरा block चलाओ", यही logic Decision Based Processing का base होता है।
Python में इस तरह के decisions लेने के लिए if, if-else और if-elif-else जैसे conditional statements इस्तेमाल किए जाते हैं, जिनकी मदद से program अलग-अलग स्थिति में अलग-अलग तरीके से behave कर सकता है।
Decision Based Processing की वजह से ही program "intelligent" behaviour दिखा पाता है, यानी हर बार same output देने की बजाय, input और condition के हिसाब से अलग-अलग output दे पाता है।
ATM machine का उदाहरण फिर से लें तो, अगर आपकी account balance amount से ज्यादा है तो पैसे निकल जाएंगे, वरना "Insufficient Balance" जैसा message आ जाएगा, यह पूरा decision उसी condition based logic पर काम करता है।
Exam की नज़र से देखा जाए तो Decision Based Processing का मतलब है – "program flow ka wo tareeka jisme ek ya ek se zyada conditions ko check karke, unke result (True/False) ke aadhar par alag-alag path execute kiya jata hai."
Decision Making in Algorithms in Hindi – Algorithm में Decision कैसे लिया जाता है?
Algorithm में जब भी decision making शामिल करनी होती है, तो सबसे पहले condition को clearly define किया जाता है, जैसे "क्या number 0 से बड़ा है" या "क्या दोनों values बराबर हैं"।
उसके बाद algorithm में दो अलग-अलग रास्ते (branches) बनाए जाते हैं – एक रास्ता तब follow होगा जब condition True निकले, और दूसरा रास्ता तब follow होगा जब condition False निकले।
कई बार सिर्फ दो नहीं, बल्कि कई सारी conditions एक साथ check करनी होती हैं, ऐसी स्थिति में algorithm में if-elif-else जैसी multiple branches का इस्तेमाल किया जाता है।
एक typical decision based algorithm कुछ इस तरह लिखा जाता है:
Step 1: Start
Step 2: Input value(s)
Step 3: Check condition
Step 4: If condition is True, go to Step 5
Else, go to Step 6
Step 5: Perform Task A, then go to Step 7
Step 6: Perform Task B
Step 7: Print result
Step 8: Stop
Algorithm लिखते समय हमेशा यह ध्यान रखा जाता है कि हर possible condition का कोई न कोई result जरूर define हो, यानी कोई भी case ऐसा नहीं छूटना चाहिए जिसका program में कोई जवाब ही न हो।
Nested decisions भी possible होते हैं, यानी एक condition के अंदर एक और condition check की जा सकती है, इसे Nested Decision Making कहा जाता है, जो complex real-world problems solve करने में काफी काम आता है।
Characteristics of Decision Based Processing in Hindi – इसकी विशेषताएं
1. Condition-Dependent Flow:
Program का execution flow पूरी तरह condition के result (True/False) पर depend करता है, यानी हर बार एक जैसा flow नहीं चलेगा।2. Multiple Paths:
Decision Based Processing में program के पास कम से कम दो अलग-अलग paths होते हैं, जिनमें से सिर्फ एक ही path किसी particular run में execute होगा।3. Boolean Evaluation:
हर condition हमेशा एक Boolean value (True या False) में evaluate होती है, इसी value के आधार पर decide होता है कि आगे कौन सा block चलेगा।4. Non-Deterministic Path (Input Based):
भले ही program का logic fixed हो, लेकिन अलग-अलग input देने पर program अलग-अलग path से गुजर सकता है, इसलिए output भी अलग-अलग हो सकता है।5. Selective Execution:
Program के सभी statements हर बार execute नहीं होते, condition के हिसाब से सिर्फ relevant block ही चलता है, बाकी statements skip हो जाते हैं।6. Supports Nesting:
एक decision के अंदर दूसरी decision रखी जा सकती है, यानी conditions को nested तरीके से भी इस्तेमाल किया जा सकता है, जिससे complex logic को handle करना आसान हो जाता है।
Decision Symbols in Flowcharts in Hindi – Flowchart में Decision Symbol
Flowchart में Decision Symbol को हमेशा Diamond (Rhombus) shape से represent किया जाता है, यह symbol उन सभी जगहों पर इस्तेमाल होता है जहां कोई condition check की जा रही हो।
Diamond के अंदर हमेशा वह condition लिखी जाती है जिसे check करना है, जैसे
num % 2 == 0?, और उसमें से हमेशा कम से कम दो arrows निकलते हैं – एक True (Yes) के लिए और एक False (No) के लिए।हर branch (True और False) आगे चलकर अपने-अपने processing steps से होते हुए, आखिर में एक ही जगह पर वापस मिल सकते हैं (जैसे ऊपर के diagram में दोनों paths Stop से पहले आपस में जुड़ रहे हैं) या फिर अलग-अलग End points पर भी खत्म हो सकते हैं।
अगर program में एक से ज्यादा conditions check करनी हों (if-elif-else जैसी situation), तो flowchart में कई सारे Decision Symbols (diamonds) एक के बाद एक इस्तेमाल किए जाते हैं।
Conditional Statements in Hindi – Python के Conditional Statements
Python में Decision Based Processing को implement करने के लिए मुख्य रूप से तीन तरह के conditional statements इस्तेमाल किए जाते हैं – if, if-else और if-elif-else।
1. Simple if Statement:
जब सिर्फ एक ही condition check करनी हो और उसके True होने पर कोई काम करना हो, तब simple if statement इस्तेमाल किया जाता है।
age = int(input("Apni age enter karo: "))
if age >= 18:
print("Aap vote de sakte hain")
2. if-else Statement:
जब condition True होने पर एक काम और False होने पर दूसरा काम करना हो, तब if-else statement इस्तेमाल किया जाता है।
num = int(input("Number enter karo: "))
if num % 2 == 0:
print("Number Even hai")
else:
print("Number Odd hai")
3. if-elif-else Statement:
जब दो से ज्यादा conditions check करनी हों, तब if-elif-else का इस्तेमाल किया जाता है, इसमें conditions को ऊपर से नीचे एक-एक करके check किया जाता है, जो भी पहली condition True मिलती है उसी का block execute होता है।
marks = int(input("Marks enter karo: "))
if marks >= 90:
print("Grade: A")
elif marks >= 75:
print("Grade: B")
elif marks >= 50:
print("Grade: C")
else:
print("Grade: Fail")
यहां ध्यान देने वाली बात यह है कि जैसे ही कोई एक condition True निकल जाती है, बाकी की elif conditions check ही नहीं होतीं, इससे program की efficiency भी बनी रहती है।
Test Whether a Number is Prime in Hindi – Prime Number Check करना
Prime Number checking Decision Based Processing का एक बहुत popular exam example है, इसमें एक number दिया जाता है और यह पता लगाना होता है कि वह Prime है या नहीं।
Prime Number वह number होता है जो सिर्फ 1 और खुद उसी number से पूरी तरह divide होता है, यानी उसका कोई और factor नहीं होता, ध्यान रहे 1 को Prime Number नहीं माना जाता।
Algorithm:
Step 1: Start
Step 2: Input n
Step 3: Set is_prime = True
Step 4: If n is less than 2, set is_prime = False
Step 5: Repeat i from 2 to n-1:
If n % i == 0, set is_prime = False, break
Step 6: If is_prime is True, print "Prime"
Else, print "Not Prime"
Step 7: Stop
Python Code:
n = int(input("Number enter karo: "))
is_prime = True
if n < 2:
is_prime = False
else:
for i in range(2, n):
if n % i == 0:
is_prime = False
break
if is_prime:
print(n, "ek Prime Number hai")
else:
print(n, "Prime Number nahi hai")
इस program में देखिए कि Decision Symbol (if condition) कई जगह इस्तेमाल हो रहा है – पहले n less than 2 check करने के लिए, फिर loop के अंदर divisibility check करने के लिए, और आखिर में final result print करने के लिए, यही पूरा concept Decision Based Processing को represent करता है।
Optimized Version (Faster Check):
बड़े numbers के लिए loop को n तक चलाने की बजाय, सिर्फ n के square root तक चलाना काफी होता है, इससे program काफी तेज हो जाता है:
import math
n = int(input("Number enter karo: "))
is_prime = n >= 2
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
is_prime = False
break
print(n, "Prime hai" if is_prime else "Prime nahi hai")
Find Largest Number in an Array in Python in Hindi – Array में सबसे बड़ी Number ढूंढना
यह भी Decision Based Processing का एक classic example है, जिसमें एक array (Python में इसे list कहा जाता है) दिया जाता है, और उसमें से सबसे बड़ी value ढूंढनी होती है।
इसका logic बहुत सीधा है – पहले array के पहले element को largest मान लिया जाता है, फिर बाकी सभी elements के साथ एक-एक करके compare (decision) किया जाता है, और जब भी कोई बड़ा element मिलता है, largest की value update कर दी जाती है।
Algorithm:
Step 1: Start
Step 2: Input array of numbers
Step 3: Set largest = array[0]
Step 4: Repeat for each element in array:
If element > largest, set largest = element
Step 5: Print largest
Step 6: Stop
Python Code:
numbers = [23, 67, 12, 89, 45, 8]
largest = numbers[0]
for num in numbers:
if num > largest:
largest = num
print("Array mein sabse badi number hai:", largest)
इस program में हर element के साथ एक Decision (if num > largest) लिया जा रहा है, यानी हर comparison पर program decide कर रहा है कि largest की value update करनी है या नहीं, यही Decision Based Processing का असली इस्तेमाल है।
Built-in Function से (Quick Method):
Python में सीधे largest निकालने के लिए एक built-in function भी होता है, हालांकि exam में हमेशा manual logic (ऊपर वाला तरीका) समझना ज्यादा जरूरी होता है:
numbers = [23, 67, 12, 89, 45, 8]
print("Sabse badi number hai:", max(numbers))
Dry Run Table (numbers = [23, 67, 12, 89, 45, 8]):
| Current Element | Condition (num > largest) | largest (after step) |
|---|---|---|
| 23 | - | 23 (initial) |
| 67 | 67 > 23 → True | 67 |
| 12 | 12 > 67 → False | 67 |
| 89 | 89 > 67 → True | 89 |
| 45 | 45 > 89 → False | 89 |
| 8 | 8 > 89 → False | 89 (Final Answer) |
Frequently Asked Questions (FAQ) – Decision Based Processing in Python in Hindi
जब program किसी condition को check करके, उसके True या False होने के आधार पर अलग-अलग statements execute करता है, तो उसे Decision Based Processing कहते हैं।
Python में Decision लेने के लिए मुख्य रूप से if, if-else और if-elif-else statements इस्तेमाल किए जाते हैं।
Flowchart में Decision को हमेशा Diamond (Rhombus) shape से represent किया जाता है, जिसमें से True और False के लिए अलग-अलग arrows निकलते हैं।
Number को 2 से लेकर उसके square root तक ही divide करके check करना सबसे efficient तरीका माना जाता है, इससे बड़े numbers के लिए भी program तेजी से result देता है।
Array के पहले element को largest मानकर, बाकी सभी elements के साथ एक-एक करके compare किया जाता है, और जब भी कोई बड़ा element मिलता है तो largest की value update कर दी जाती है, या फिर Python के built-in max() function का भी इस्तेमाल किया जा सकता है।