while döngüsü

Orta Seviye Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

if-elif-else

control.py

  • Yapıdan yalnızca bir kez geçer!
z = 6
if z % 2 == 0 :  # True
    print("z is divisible by 2")  # Çalıştı
elif z % 3 == 0 :
    print("z is divisible by 3")
else :
    print("z is neither divisible by 2 nor by 3")

...   # Devam ediyoruz
  • While döngüsü = tekrar eden if deyimi
Orta Seviye Python

While

while condition :
    expression
  • Sayısal olarak model hesaplama
  • "koşul sağlanana kadar tekrarlama"
  • Örnek
    • Hata 50’den başlar
    • Her çalıştırmada hatayı 4’e bölün
    • Hata artık > 1 olmayana dek sürdürün
Orta Seviye Python

While

while condition :
    expression

while_loop.py

error = 50.0


while error > 1:
error = error / 4
print(error)
  • Hata 50’den başlar
  • Her çalıştırmada hatayı 4’e bölün
  • Hata artık > 1 olmayana dek sürdürün
Orta Seviye Python

While

while condition :
    expression

while_loop.py

error = 50.0
#     50
while error > 1:    # True
      error = error / 4
      print(error)
12.5
Orta Seviye 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
Orta Seviye 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
Orta Seviye 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
Orta Seviye 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: oturum kesildi
  • Yerel sistem: Control + C
Orta Seviye Python

Hadi pratik yapalım!

Orta Seviye Python

Preparing Video For Download...