while loop

इंटरमीडिएट Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

if-elif-else

control.py

  • यह construct सिर्फ एक बार चलता है!
z = 6
if z % 2 == 0 :  # True
    print("z is divisible by 2")  # Executed
elif z % 3 == 0 :
    print("z is divisible by 3")
else :
    print("z is neither divisible by 2 nor by 3")

...   # Moving on
  • While loop = बार-बार चलने वाला if स्टेटमेंट
इंटरमीडिएट Python

While

while condition :
    expression
  • संख्या-आधारित मॉडल कैलकुलेशन
  • "शर्त पूरी होने तक क्रिया दोहराएँ"
  • उदाहरण
    • त्रुटि 50 से शुरू होती है
    • हर रन में त्रुटि को 4 से भाग दें
    • तब तक चलाएँ जब तक त्रुटि > 1 न रहे
इंटरमीडिएट Python

While

while condition :
    expression

while_loop.py

error = 50.0


while error > 1:
error = error / 4
print(error)
  • त्रुटि 50 से शुरू होती है
  • हर रन में त्रुटि को 4 से भाग दें
  • तब तक चलाएँ जब तक त्रुटि > 1 न रहे
इंटरमीडिएट Python

While

while condition :
    expression

while_loop.py

error = 50.0
#     50
while error > 1:    # True
      error = error / 4
      print(error)
12.5
इंटरमीडिएट Python

While

while condition :
    expression

while_loop.py

error = 50.0
#     12.5
while error > 1:    # True
      error = error / 4
      print(error)
12.5
3.125
इंटरमीडिएट Python

While

while condition :
    expression

while_loop.py

error = 50.0
#     3.125
while error > 1:    # True
      error = error / 4
      print(error)
12.5
3.125
0.78125
इंटरमीडिएट Python

While

while condition :
    expression

while_loop.py

error = 50.0
#     0.78125
while error > 1:    # False
    error = error / 4
    print(error)
12.5
3.125
0.78125
इंटरमीडिएट Python

While

while condition :
    expression

while_loop.py

error = 50.0
while error > 1 :    # always True
    # error = error / 4
    print(error)
50
50
50
50
50
50
50
...
  • DataCamp: session डिसकनेक्ट हो जाएगा
  • लोकल सिस्टम: Control + C
इंटरमीडिएट Python

अभ्यास करते हैं!

इंटरमीडिएट Python

Preparing Video For Download...