** Python Day 8 – While Loop Practice Programs (1 to 8)**
1) 1 1 1 1 1
Code
i = 1
while i <= 5:
print(1, end=" ")
i += 1
Output
1 1 1 1 1
2) 1 2 3 4 5
Code
i = 1
while i <= 5:
print(i, end=" ")
i += 1
Output
1 2 3 4 5
3) 1 3 5 7 9
Code
i = 1
while i <= 9:
print(i, end=" ")
i += 2
Output
1 3 5 7 9
4) 3 6 9 12 15
Code
i = 3
while i < 16:
print(i, end=" ")
i += 3
Output
3 6 9 12 15
4.1) 15 12 9 6 3
Code
i = 15
while i > 1:
print(i, end=" ")
i -= 3
Output
15 12 9 6 3
4.2) 10 8 6 4 2
Code
i = 10
while i > 1:
print(i, end=" ")
i -= 2
Output
10 8 6 4 2
4.3) 9 7 5 3 1
Code
i = 9
while i > -1:
print(i, end=" ")
i -= 2
Output
9 7 5 3 1
5) Multiple of 3 and 5
Code
a = int(input("Enter a number: "))
if a % 3 == 0 and a % 5 == 0:
print("Multiple of 3 and 5")
else:
print("Not a multiple of 3 and 5")
Sample Output
Enter a number: 15
Multiple of 3 and 5
6) Multiple of 3 or 5
Code
a = int(input("Enter a number: "))
if a % 3 == 0 or a % 5 == 0:
print("Multiple of 3 or 5")
else:
print("Not a multiple of 3 or 5")
Sample Output
Enter a number: 10
Multiple of 3 or 5
7) Divisors of a Given Number
Code
a = int(input("Enter a number: "))
i = 1
while i <= a:
if a % i == 0:
print(i, end=" ")
i += 1
Sample Output
Enter a number: 12
1 2 3 4 6 12
8) Count of Divisors of a Given Number
Code
a = int(input("Enter a number: "))
count = 0
i = 1
while i <= a:
if a % i == 0:
count += 1
i += 1
print(count)
Sample Output
Enter a number: 12
6
CONCULSTION
- Today i have do the pratice the 15 question and do 8 question remainig question i have some promblem mathematically problem i have and 9,10,11,12,13,14,15 i am known the program wise and not able to known this question understand there realy what happens in the sum how like means not 5x5=10 i known that i known but known 45 then ask means iam d'not known have can slove the problem practical iam able the remaing question the code how can run i will understand where come but logicaly what happens there number iam dont known
Top comments (0)