Title: Solving Common Python Problems: A Practical Approach
Summarise what you learned from solving each problem. This helps readers understand the importance of the problems and encourages them to explore similar challenges.
#1) Count of Digits
given_number=1234;
count=0
while given_number>0:
digit=given_number%10;
count+=1;
given_number=given_number//10;
print(count)
#2) Sum of Digits
given_answe=274;
count=0;
sum=0;
while given_answe>0:
digits=given_answe%10;
count+=1
sum=sum+digits;
given_answe=given_answe//10;
print(count);
print(sum)
#3) Reverse the number
Given_number_ans=12345;
reversed_num=0;
while Given_number_ans>0:
digits=Given_number_ans%10;
reversed_num=(reversed_num*10)+digits
Given_number_ans=Given_number_ans//10;
print(reversed_num)
#4) Factorial
#n!=n*(n-1)*(n-2)...
N=5;
i=1;
total=1;
while(i<=N):
total=total*i;
i+=1;
print(f'sum of Factorial is {N} is {total}')
#5) Greatest Common Divisor
Number1=36;
Number2=94;
Gcd=0;
smallest=min(Number1,Number2);
for i in range(1,smallest+1):
if Number1%i==0 and Number2%i==0:
Gcd=i;
print(f"The GCD of {Number1} and {Number2} is {Gcd}")
Top comments (0)