0% found this document useful (0 votes)
3 views1 page

Imph

The document contains Python code snippets demonstrating various programming concepts, including calculating the sum of digits, reversing a number, checking for prime numbers, and determining if a string is a palindrome. It utilizes loops, conditionals, and built-in functions to perform these tasks. Each section of code is labeled with comments indicating the concept being illustrated.

Uploaded by

iitbombay890
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Imph

The document contains Python code snippets demonstrating various programming concepts, including calculating the sum of digits, reversing a number, checking for prime numbers, and determining if a string is a palindrome. It utilizes loops, conditionals, and built-in functions to perform these tasks. Each section of code is labeled with comments indicating the concept being illustrated.

Uploaded by

iitbombay890
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

num = int(input("Enter the number")) name=input("Enter the name")

n=num
sum=0 l=len(name) #inbuilt func on to store length of a
while(n>0): string
rem=n%10 print(l)
sum=sum+rem
n=int(n/10) ch=input("Enter the character")
print(sum) c=name.count(ch) #Inbuilt func on to check a
string in another string
print(c)

rev=""
SUM 0F DIGITS for i in name:
rev=i+rev
print(rev)

BASICS OF STRING + REVERSE


n=int(input("Enter the number")) num = int(input("Enter the number"))
rev=0 c=0
while(n>0): for i in range(2,num):
rem=n%10 if num%i==0:
rev=rev*10+rem c=1
n=int(n/10) break #To leave the current loop
print(rev) if c==0:
print("Prime Number")
REVERSE OF NUMBER else:
print("Not Prime Number")

PRIME NUMBER
n=int(input("Enter the number")) n = int(input("Enter the number"))
for i in range(1,n+1):
for j in range(1,n-i+2): for i in range(1,n+1): #Number of rows
print(n-j+1,end=" ") for j in range(1,i+1): #Number of columns
print() print(j,end=" ")#Prin ng in single line
print()
54321 1
5432 12
543 123
54 1234
5 12345
s1=input("Enter the string ") n=int(input("enter the number"))
f=1
rev="" for i in range(1,n+1):
for i in s1: f=f*i
rev=i+rev print(f)

if rev==s1: FACTORIAL
print("Palindrome")
else:
print("Not Palindrome")
PALINDROME

You might also like