Page 79 - TP_V5.1_C8_fb
P. 79
On running the above program, we get the following output:
Output
1
2
3
4
5
6
7
8
9
Program 12: To display the first 5 powers of 2.
Program12.py
File Edit Format Run Options Window Help
# Print the first 5 powers of 2
for i in range(5):
print(2 ** i)
On running the above program, we get the following output:
Output
1
2
4
8
16
Program 13: To count the number of digits in a number.
Program13.py
File Edit Format Run Options Window Help
# Count the number of digits in a number
num = 123456
count = 0
while num > 0:
num //= 10
count += 1
print("Sum of even numbers from 1 to 50:", sum_even)
Iterations in Python 77

