Level:2 Tasks
1) 7, 10, 8, 11, 9, 12, 10
# 7,10,8,11,9,12,10
no = 7
count = 0
while count < 7:
print(no, end=",")
if count % 2 == 0:
no += 3
else:
no -= 2
count += 1
Output:
7,10,8,11,9,12,10,
2) 36, 34, 30, 28, 24, 22
num = 36
diff=2
while num >= 22:
print(num, end=",")
if diff==2 :
num -= diff
diff=4
else:
num -= diff
diff=2
Output:
36,34,30,28,24,22,
3) 22, 21, 23, 22, 24, 23
# 22, 21, 23, 22, 24, 23
num = 22
diff=1
while num <= 24:
print(num, end=",")
if diff==1 :
num -= diff
diff+=1
else:
num += diff
diff=1
Output:
22,21,23,22,24,23,
4) 53, 53, 40, 40, 27, 27
# 53, 53, 40, 40, 27, 27
num = 53
diff=13
while num >= 27:
print(num,num, end=",")
if diff==13 :
num -= diff
else:
break
5) 21, 9, 21, 11, 21, 13, 21
fixed_number = 21
no = 9
count = 0
while count < 7:
if count % 2 == 0:
print(fixed_number, end=', ')
else:
print(no, end=', ')
no += 2
count += 1
Output:
21, 9, 21, 11, 21, 13, 21,
6) 3, 4, 7, 8, 11, 12
# 3, 4, 7, 8, 11, 12
no = 3
count = 0
while count < 6:
if count % 2 == 0:
print(no, end=', ')
else:
print(no+ 1, end=', ')
no += 4
count += 1
Output:
3, 4, 7, 8, 11, 12,
7) 14, 28, 20, 40, 32, 64
no = 14
difference = 8
count = 0
while count < 6:
if count % 2 == 0:
print(no, end=', ')
no *= 2
else:
print(no, end=', ')
no-=8
count += 1
Output:
14, 28, 20, 40, 32, 64,
Top comments (0)