-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_Loops.py
60 lines (51 loc) · 1.15 KB
/
05_Loops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# For loop
num1 = int(input("Bir sayi giriniz: "))
count = 1
while count <= num1:
print(count)
count += 1
# 5 x 4
num2 = int(input("İkinci bir sayi giriniz: "))
count = 0
result = 0
# Multiply with while
while count < num1:
result += num2
count += 1
print(str(num1) + " * " + str(num2) + " = " + str(result))
# Multiply with for
result = 0
for i in range(0, num1):
result += num2
print(str(num1) + " * " + str(num2) + " = " + str(result))
# For loop with array
fruits = ["elma", "muz", "kivi", "erik"]
for x in fruits:
print(x)
# Does contains with for loop
flag = False
key = input("Meyve adi girin: ")
for x in fruits:
if x == key:
# print("Kivi array'de var.")
flag = True
break
if flag:
print(key + " arrayde var.")
else:
print(key + " arrayde yok.")
# Does contains with for loop
location = -1
key = input("Meyve adi girin: ")
for index,x in enumerate(fruits):
if x == key:
location = index
break
print(key + " indexi " + str(location))
for i in range(0, 5):
if i == 3:
continue
print(i)
numbers = [1.73, 1.68, 1.71, 1.89]
for num in numbers:
print(num)