December 23, 2020

 

#To check of entered number is an Armstrong number

num = input('enter a number : ')

l = len(num)

num1 = int(num)

num2 = num1

result = 0

while num1 > 0 :

digit = num1%10

result = (digit**l) + result

num1 = num1//10

if num2 == result:

print('Number is armstrong')

else:

print('Number is not armstrong')


#L.C.M. -

num1 = int(input('Enter 1st number : '))

num2 = int(input('Enter 2nd number : '))

if num2>num1:

min = num1

else:

min = num2

while(1):

if min%num1 == 0 and min%num2 == 0:

print(min)

break

min += 1


#Check Leap Year

year = int(input('Enter Year : '))

if (year % 4) == 0 :

if (year % 100) == 0 :

if (year % 400) == 0 :

print(year , 'is a Leap Year')

else :

print(year , 'is not a Leap Year')

else :

print(year , 'is a Leap Year')

else :

print(year , 'is not a Leap Year')



print(""" INPUT :

>>> square - Square of a digit,

>>> cube - Cube of a digit,

>>> add - Add,

>>> div - Divide,

>>> prod - Multiply,

>>> dif - Subtract or Difference,

>>> rev - To Reverse a Number,

>>> prime - To check Prime Number,

>>> odde - To check Odd or Even,

>>> sr - To find Square Root,

>>> cr - To find Cube Root \n""")

def square(x):

print(x*x)

def cube(x):

print(x*x*x)

def add(x,y):

print(x+y)

def dif(x,y):

print(x-y)

#Enter Required Operation

ops = input('Enter Operation : ')

#If Operation = Square

if ops == 'square' :

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

print('Square of', num, 'is' , end = ' ')

square(num)

exit()

#If Operation = Cube

if ops == 'cube' :

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

print('Cube of', num, 'is' , end = ' ')

cube(num)

exit()

#If Operation = Addition

if ops == 'add':

num1 = int(input('Enter a first number : '))

num2 = int(input('Enter a second number : '))

add(num1,num2)

exit()

#If Operation = Subtraction

if ops == 'dif' :

num1 = int(input('Enter a first number : '))

num2 = int(input('Enter a second number : '))

dif(num1,num2)

exit()

#If Operation = Cube Root

if ops == 'cr' :

n = float(input('Enter Number : '))

root = n**0.333333333333333333333333333333333333333333333333333333333333333333

print('Cube root of', n ,'is' ,root)

exit()

#If Operation = Square Root

if ops == 'sr' :

n = float(input('Enter Number : '))

root = n**0.5

print('Square root of', n ,'is' ,root)

exit()

#To check for a Prime Number

if ops == 'prime' :

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

if number > 1:

for i in range(2, number):

if (number % i) == 0:

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

break

else:

print(number, "is a prime number")

else:

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

exit()

#To check if a number is Even or Odd

if ops == 'odde' :

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

if num>1 :

if num%2 > 0 :

print(num, 'is an odd number')

else :

print(num, 'is an even number')

else:

print(num, 'is an odd number')

exit()

#If Operation = Divide

if ops == 'divide' :

num1 = float(input('Enter number 1 : '))

num2 = float(input('Enter number 2 : '))

divide = num1/num2

print(divide)

exit()

if ops == 'prod' :

num1 = float(input('Enter number 1 : '))

num2 = float(input('Enter number 2 : '))

product = num1*num2

print(product)

exit()

#If Operation = Reverse

if ops == 'rev' :

num = int(input('enter a number : '))

rev = 0

while num != 0 :

digit = num % 10

rev = (rev * 10) + digit

num = num//10

print('Reverse of number is', rev)

exit()

Loading...
Comments