Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 99387fc

Browse files
30 python practice programs completed.
1 parent 0154a4d commit 99387fc

5 files changed

+67
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Description:
3+
4+
This is the same program as program#24. In this program we print first n even numbers like
5+
if n = 3 then the program prints 2,4,6
6+
"""
7+
8+
n = int(input('How many even numbers from starting you want to print? '))
9+
i = 1
10+
count = 0
11+
while count < n:
12+
if i % 2 == 0:
13+
print(i)
14+
count += 1
15+
i += 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Description:
2+
.) Same as program#25
3+
"""
4+
5+
no = int(input('Enter Number to find sum of squares of digits of a number: '))
6+
sum = 0
7+
while no > 0:
8+
sum += ((no % 10) ** 2)
9+
no //= 10
10+
print('The sum of square of each digit =', sum)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Description:
2+
.) Same as program#27
3+
"""
4+
5+
no = int(input('Enter Number to find sum of cubes of digits of a number: '))
6+
sum = 0
7+
while no > 0:
8+
sum += ((no % 10) ** 3)
9+
no //= 10
10+
print('The sum of cube of each digit =', sum)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Description:
3+
4+
Armstrong numbers are those in which we find sum of cubes of each digit of a number and
5+
in the armstrong number case lets say if user enters a number 153 so
6+
1***3 + 5***3 + 3***3
7+
1 +γŸγ™ 125 +γŸγ™ 27 =わ 153, so as we see the sum number returns even after we calculate sum of cubes of
8+
each digit of a number so it means 153 is an armstrong number.
9+
10+
"""
11+
12+
no = int(input('Enter Number to check whether it is armstrong or not: '))
13+
orginalNumber = no
14+
sum = 0
15+
while no > 0:
16+
sum = sum + ((no % 10) ** 3)
17+
no = no // 10
18+
if sum == orginalNumber:
19+
print('The Number is armstrong.')
20+
else:
21+
print('The number is not armstrong.')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Description:
3+
Same logic like Program#25.
4+
"""
5+
6+
no = int(input('Enter Number to find product of digits of a number: '))
7+
product = 1 # for sum we initialize sum to 0 but for product we initialize product to 1.
8+
while no > 0:
9+
product = product * (no % 10)
10+
no = no // 10
11+
print('Product of digits of a number =', product)

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /