To accept the number and compute using python
a)Square root a Number
>>> num = float(input('Enter a Number:'))
Enter a Number:77
>>> num_sqrt = num ** 0.5
>>> print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
The square root of 77.000 is 8.775
>>>
b)Squar of a Number
>>> num = float(input('Enter a Number:'))
Enter a Number:12
>>> square = num * num
>>> print('The square of %0.3f is %0.3f'%(num ,square))
The square of 12.000 is 144.000
>>>
c)Cube of a Number
>>> num = float(input('Enter a Number:'))
Enter a Number:4
>>> cube= num * num *num
>>> print('The cube of %0.3f is %0.3f'%(num ,cube))
The cube of 4.000 is 64.000
d)Check for Prime Number
>>> num = int(input("Enter a number: "))
Enter a number: 23
>>> if num > 1:
... for i in range(2, num):
... if(num % i) == 0:
... print(num,"IS NOT APRIME NUMBER")
... break
... else:
... print(num,"IS A PRIME NUMBER")
... else:
... print(num,"IS NOT A PRIME NUMBER")
...
23 IS A PRIME NUMBER
5) factorial of number
>>> num = int(input('Enter a Number:'))
Enter a Number:23
>>> f = 1
>>> if(num < 0):
... print("THE NUMBER IS NEGATIVE")
... elif(num == 0):
... print("The factorial of 0 is 1")
... else:
... for i in range (1, num + 1):
... f =f * i
... print("the factorial of",num,"is",f)
...
the factorial of 23 is 25852016738884976640000
>>>
No comments:
Post a Comment