-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compute.py
53 lines (49 loc) · 1.07 KB
/
Compute.py
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
49
50
51
52
53
import string
str=string.ascii_letters
#Prime Number
def prime(p):
if p==1:
print('1 is a uniqe number')
elif p%2==0:
print('Not a Prime Number')
elif p%2!=0:
for i in range (3,int(p**0.5),2):
if p%i==0:
print('Not a Prime number')
break
else:
print('Prime number found')
#Factorial
def fact(n):
if n==0:
return 1
return n*fact(n-1)
#Prime Factor
def pfact(p):
print('Prime factors =',end=' ')
while p%2==0:
print(2,end=' , ')
p/=2
for i in range (3,int(p**0.5),2):
while p%i==0:
print(i,end=' , ')
p/=i
if p>2:
print(p)
p=int(input('Enter a number : '))
while 1:
print('Square root of the number is =',p**0.5)
print('Square of the number is =',p**2)
print('Cube of the number is =',p**3)
print(f'\nFactorial of the number is = {p}! = {fact(p)}')
prime(p)
pfact(p)
def fun():
fun.a=input('\nEnter a new number (enter 0 to stop) : ')
if fun.a=='0':
exit()
elif (any(x in str for x in fun.a)):
print('Enter a number or 0 only')
fun()
fun()
p=int(fun.a)