0% found this document useful (0 votes)
47 views6 pages

PYTHON Prog

The document contains code snippets for several Python programs that demonstrate basic concepts like loops, conditionals, strings, lists, and functions. The programs include: 1. A multiplication table that prints the results of multiplying a user-input number by integers from 0 to 10. 2. A program that calculates the sum of the digits in a user-input number. 3. A program that determines if a user-input number is even or odd. 4. A program that checks if a user-input number is a prime number. 5. Programs that check if a number is a palindrome and find the index of a character in a string. So in summary, the document

Uploaded by

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

PYTHON Prog

The document contains code snippets for several Python programs that demonstrate basic concepts like loops, conditionals, strings, lists, and functions. The programs include: 1. A multiplication table that prints the results of multiplying a user-input number by integers from 0 to 10. 2. A program that calculates the sum of the digits in a user-input number. 3. A program that determines if a user-input number is even or odd. 4. A program that checks if a user-input number is a prime number. 5. Programs that check if a number is a palindrome and find the index of a character in a string. So in summary, the document

Uploaded by

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

Multiplication Table

print("Enter a number:")

x=input()

for i in range(0,11):

a=i*x

print(x,"*",i,"=",a)

i+=1

OUTPUT

Enter a number:

2*0=0

2*1=2

2*2=4

2*3=6

2*4=8

2 * 5 = 10

2 * 6 = 12

2 * 7 = 14

2 * 8 = 16

2 * 9 = 18

2 * 10 = 20

Sum of digits
print("Enter a number:")

x=input()

x=int(x)

sum=0

while(x>0):

n=x%10

sum=sum+n
sum=int(sum)

x=x/10

print("Sum of the digits of","=",sum)

OUTPUT

Enter a number:

123

Sum of the digits of = 6

even/odd
print("Enter a number:")

x=input()

x=int(x)

if(x%2==0):

print("Even number")

else:

print("Odd number")

OUTPUT

Enter a number:

Even number

Enter a number:

Odd number

Prime number
print("Enter a number")

num = int(input())

if num > 1:

for i in range(2,num):

if (num % i) == 0:
print(num,"is not a prime number")

else:

print(num,"is a prime number")

OUTPUT

Enter a number

2 is a prime number

Palindrome
n=int(input("Enter number:"))

temp=n

rev=0

while(n>0):

dig=n%10

rev=rev*10+dig

n=n//10

if(temp==rev):

print("The number is a palindrome!")

else:

print("The number isn't a palindrome!")

OUTPUT

Enter number:16461

The number is a palindrome!

Enter number:123

The number isn't a palindrome!


STRING PROGRAMMES

Index of a character
st="This is input string"

a=0

print("In:",st,",i occured at")

for x in st:

if x=="i":

print(a)

a=a+1

OUTPUT

In: This is input string ,i occured at

17

Anagrams
s1=input("Enter string 1")

s2=input("Enter string 2")

if(sorted(s1)== sorted(s2)):

print("anagrams")

else:

print("not anagrams")

Count Number of words, print 2nd word

OUTPUT

Enter string 1 abc


Enter string 2 bac

anagrams

Enter string 1 rit

Enter string 2 ter

not anagrams

Characters occurred most in a string


s=input("Enter string")

num=0

for i in range(0,len(s)):

for j in range(i+1,len(s)):

if(s[i]==s[j]):

num=num+1

print("Char",s[i],"ocuured",num,"times in the string")

OUTPUT

??

REVERSAL OF A STRING
s=input("Enter string")

rev=s[::-1]

print(rev)

OUTPUT

s=input("Enter string")

rev=s[::-1]

print(rev)
LISTS

You might also like