0% found this document useful (0 votes)
26 views9 pages

Assignment 6

Uploaded by

vijay.23mic7015
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)
26 views9 pages

Assignment 6

Uploaded by

vijay.23mic7015
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/ 9

Assignment – 6

Roll Number: 23MIC7015


Name of The Student:
K. VIJAY KUMAR
Slot &Date: L35+L36

1) Write a python program to check whether a number is palindrome or not.

num=int(input("Enter a number:"))

temp=num

rev=0

rem=0

while(num>0):

rem=num%10

rev=rev*10+rem

num=num//10

if (temp==rev):

print("The number is a palindrome.")

else:

print("The number is not a palindrome.")

Output:

Enter a number:1234554321

The number is a palindrome.


2) Write a python program to find frequency of each digit in a given integer

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

print("Digit\tfrequency")

for i in range(0,10):

count=10

temp=n

while temp>0:

digit=temp%10

if digit==i:

count=count+1

temp=temp//10

if count>0:

print(i,"is repeated",count,"times")

Output:

Enter any number:90

Digit frequency

0 is repeated 1 times

9 is repeated 1 times

3) Write a python program to print all ASCII character with their values.

i=0

while i<=255:

print(i,"=",chr(i),end='\t')

i+=1

Output:

0= 1= 2= 3= 4= 5= 6= 7= 8= 9= 10 =
11 =
12 = 13 =
14 = 15 = 16 = 17 = 18 = 19 = 20 = 21 = 22 = 23 = 24 =
25 = 26 = 27 = 28 = 29 = 30 = 31 = 32 = 33 = ! 34 = " 35 = #
36 = $ 37 = % 38 = & 39 = ' 40 = ( 41 = ) 42 = * 43 = + 44 = , 45 = - 46 = .
47 = / 48 = 0 49 = 1 50 = 2 51 = 3 52 = 4 53 = 5 54 = 6 55 = 7 56 = 8 57 = 9
58 = : 59 = ; 60 = < 61 = = 62 = > 63 = ? 64 = @65 = A 66 = B 67 = C 68 = D
69 = E 70 = F 71 = G 72 = H 73 = I 74 = J 75 = K 76 = L 77 = M 78 = N 79 = O
80 = P 81 = Q 82 = R 83 = S 84 = T 85 = U 86 = V 87 = W88 = X 89 = Y 90 = Z
91 = [ 92 = \ 93 = ] 94 = ^ 95 = _ 96 = ` 97 = a 98 = b 99 = c 100 = d
101 = e 102 = f 103 = g 104 = h 105 = i 106 = j 107 = k
108 = l 109 = m 110 = n 111 = o 112 = p 113 = q
114 = r 115 = s 116 = t 117 = u 118 = v 119 = w 120 = x
121 = y 122 = z 123 = { 124 = | 125 = } 126 = ~ 127 = 
128 = € 129 =  130 = ‚ 131 = ƒ 132 = „ 133 =
134 = † 135 = ‡ 136 = ˆ 137 = ‰ 138 = Š 139 = ‹
140 = Œ 141 =  142 = Ž 143 =  144 =  145 = ‘
146 = ’ 147 = “ 148 = ” 149 = • 150 = – 151 = —
152 = ˜ 153 = ™ 154 = š 155 = › 156 = œ 157 = 
158 = ž 159 = Ÿ 160 = 161 = ¡ 162 = ¢ 163 = £ 164 = ¤
165 = ¥ 166 = ¦ 167 = § 168 = ¨ 169 = © 170 = ª171 = «
172 = ¬ 173 = 174 = ® 175 = ¯ 176 = °177 = ± 178 = ²
179 = ³ 180 = ´ 181 = µ 182 = ¶ 183 = · 184 = ¸ 185 = ¹ 186 = º 187 = »
188 = ¼ 189 = ½ 190 = ¾ 191 = ¿ 192 = À 193 = Á
194 = Â 195 = Ã 196 = Ä 197 = Å 198 = Æ 199 = Ç
200 = È 201 = É 202 = Ê 203 = Ë 204 = Ì 205 = Í 206 = Î
207 = Ï 208 = Ð 209 = Ñ 210 = Ò 211 = Ó 212 = Ô
213 = Õ 214 = Ö 215 = × 216 = Ø 217 = Ù 218 = Ú
219 = Û 220 = Ü 221 = Ý 222 = Þ 223 = ß 224 = à
225 = á 226 = â 227 = ã 228 = ä 229 = å 230 = æ
231 = ç 232 = è 233 = é 234 = ê 235 = ë 236 = ì
237 = í 238 = î 239 = ï 240 = ð 241 = ñ 242 = ò 243 = ó
244 = ô 245 = õ 246 = ö 247 = ÷ 248 = ø 249 = ù
250 = ú 251 = û 252 = ü 253 = ý 254 = þ 255 = ÿ

4) Write a python program to find all factors of a number

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

print("The factors of",n,"are:")

for i in range (1,n+1):

if n%i==0:

print(i,end=' ')

Output:

Enter any number:45

The factors of 45 are:

1 3 5 9 15 45
5) Write a python program to calculate the factorial of a number

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

fact=1

if n<0:

print("Factorials do not exist for negative numbers.")

elif n==0:

print("The factorial of 0 is 1")

else:

for i in range (1,n+1):

fact=fact*i

print("The factorial of",i,"is",fact)

Output:

Enter any number:98

The factorial of 98 is

942689044888324774562618574305724247380969376407895166349423877729470707

002322379888297615920772911982360585058860846042941264756736000000000000

0000000000

6) Write a python program to print all prime numbers between 1 to n.

n=int(input("Upto which no.:"))

count=0

print("the prime numbers from 1 to",n,"are:")

for i in range(1,n+1):

count=0

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

if(i%j==0):

count+=1

if count==2:

print(i,end=' ')
Output:

Upto which no.:99

the prime numbers from 1 to 99 are:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

7) Write a python program to print Fibonacci series upto n terms.

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

a=0

b=1

print("The fibonacci series upto",n,"is")

c=a+b

while (c<=n):

print(c,end=' ')

a=b

b=c

c=a+b

8) Write a python program to print Fibonacci series upto n terms.

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

a=0

b=1

print("The fibonacci series upto",n,"is")

c=a+b

while (c<=n):

print(c,end=' ')

a=b

b=c

c=a+b
Ouput:

Enter any number:9

The fibonacci series upto 9 is

12358

8) Write a python program to check whether a number is armstrong number or strong


number or prime number or perfect number or magic number or not

print("menu list")

print(".........")

print("1. for checking armstrong number")

print("2. for checking strong number")

print("3. for checking prime number")

print("4. for checking perfect number")

print("5. for checking magic number")

choice=int(input("Enter the number:"))

#Armstrong number

if (choice==1):

num=int(input("Enter any number:"))

order=len(str(num))

sum=0

temp=num

while temp>0:

digit=temp%10

sum+=digit**order

temp//=10

if num==sum:

print(num,"is an Armstrong number.")

else:

print(num,"is not an Armstrong number.")

#Strong number

if (choice==2):
sum=0

num=int(input("Enter any number:"))

temp=num

while(num):

i=1

fact=1

rem=num%10

while(i<=rem):

fact=fact*i

i=i+1

sum=sum+fact

num=num//10

if (sum==temp):

print(temp," is a strong number")

else:

print(temp,"is not a strong number")

#Prime number

if(choice==3):

num=int(input("Enter a number:"))

count=0

for i in range(1,num+1):

if num%i==0:

count=count+1

if count==2:

print(num,"is a prime number")

else:

print(num,"is not a prime number")

#Perfect number

if (choice==4):
n=int(input("Enter any number:"))

sum=0

for i in range(1,n):

if n%i==0:

sum=sum+i

if(sum==n):

print(n,"is a perfect number")

else:

print(n,"is not a perfect number")

#Magic number

if (choice==5):

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

sum=0

while(n>0 or sum>9):

if(n==0):

n=sum

sum=0

sum=sum+n%10

n=int(n/10)

if(sum==1):

print(n,"is Magic number")

else:

print(n,"is not a Magic number")

Output:

menu list

.........

1. for checking armstrong number

2. for checking strong number

3. for checking prime number

4. for checking perfect number


5. for checking magic number

Enter the number:4

Enter any number:69

69 is not a perfect number

You might also like