If condition -
python में if condition का उपयोग हमारे द्वारा दी गयी condition के हिसाब से निर्णय लेने में होता है |
Let’s master it step by step:-
✱लॉजिकल condition जिसका use if में होता है
x==y equal to
x!=y not equal to
x<y less than
x>y greater than
x<=y less than equal to
x>=y greater than equal to
1.हम नंबर के साथ if condition लगाते है
x=10
y=20
if x<y :
print('x is less than y')
x=10
x की value
y=20
y की value
if x<y :
यदि x<y ,:=indent (4 spaces or 1 Tab)
print('x is less than y')
प्रिंट करो - जो भी आप करवाना चाहते हो
2.यदि पहली condition सही नहीं होती है तो 2nd,3rd,4th condition के लिए elif और अंतिम condition के लिए else का भी use कर सकते है
x=10
y=20
if x>y :
print('x is greater than y')
elif x==y:
print('x is equal to y')
else :
print('x is less than y')
x=10
y=20
if x>y:
यदि x>y
print('x is greater than y')
elif x==y :
यदि x==y
print('x is equal to y')
3. if का प्रयोग and , or logical operator के साथ
and - इसमें दोनों condition true होनी चाहिए
x=10
y=20
if x<=y and x<y:
यदि x<=y तथा x<y
print('x is equal or less than y')
elif x>y :
यदि x>y
print('x is greater than y')
# and
x=10
y=20
if x<=y and x<y:
print('x is equal or less than y')
elif x>y :
print('x is greater than y')#or
x=10
y=20
if x==y or x<y:
print('x is equal or less than y')
elif x>y :
print('x is greater than y')
or- इसमें केवल एक या दोनों condition true होनी चाहिए
x=10
y=20
if x==y or x<y:
यदि x==y या x<
print('x is equal or less than y')
elif x>y :
print('x is greater than y')
4. pass statement - अगर condition तो true होती है but हमें कोई काम नहीं करवाना होता है तो हम pass का use करते है |
x=1
if x==1 :
pass
x=1
if x==1:
pass
5. if condition, if condition में
a=1234
b=int(input('write pass'))
if b==a:
print('access allowed')
c='+','-','*','/'
d=input('select the option:+ - */')
if d=='+' :
x=int(input('write 1st num '))
y=int(input('write 2nd num '))
z=x+y
print('your result is',x+y)
else :
print('access denied ,your password is wrong')
a=1234
b=int(input('write password'))
b=integer(संख्या होनी चाहिए (यूजर से इनपुट लो ('write password'))
if b==a:
yadi b==a मतलब की यूजर के द्वारा दिया गया password a के equal है तो
print('access allowed')
प्रिंट करो ('access allowed')
c='+','-'
c की value रखते है + जोड़ के लिए और - बाकि के लिए
d=input('select the option:+ - */')
फिर से user से इनपुट लेते है
if d=='+' :
यदि यूजर + सेलेक्ट करता है tतो
x=int(input('write 1st num '))
y=int(input('write 2nd num '))
फिर से 2 संख्या लो जिसे ऐड करवाना है
z=x+y
ऐड करो
print('your result is',x+y)
प्रिंट कर दो
else :
यदि नहीं ( मतलब की यूजर का password same नहीं है तो)
print('access denied ,your password is wrong')
🎯 Task for You: (give answer in comment)
1. एक सिंपल कैलकुलेटर बनाइए if condition का use करके ?
2. नीचे दिए गए कोड में एरर find कीजिये और सही कीजिये ?
x=input(int('write your age'))
if x==18:
print('you are eligible ')
else :
print('sorry you are not eligible ')
3. क्या इस कोड में कोई एरर आएगा ?
if True :
pass
4.if condition का use करके odd, even check करने का कोड बनाइए वो भी एक लाइन में ?
Your comment means a lot to us.
No comments:
Post a Comment