forked from IEEE-VIT/playing-with-numbers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
84 lines (74 loc) · 1.59 KB
/
app.py
File metadata and controls
84 lines (74 loc) · 1.59 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def add():
x = int(input("Enter your number 1: "))
y = int(input("Enter your number 2: "))
z = x+y
print("Your final result is: ", z)
def multiply():
x = int(input("Enter your number 1: "))
y = int(input("Enter your number 2: "))
z = x*y
print("Your final result is: ", z)
def factorial():
x = int(input("enter your number:"))
if x < 0:
print("Factorial does not exist for negative numbers")
elif x == 0:
print("The factorial of 0 is 1.")
else:
factorial=1
for i in range(1,x + 1):
factorial = factorial*i
print("The factorial of",x,"is",factorial)
def prime():
num = int(input("Enter a number: "))
if num>1:
flag=0
for i in range(2,num):
if (num % i) == 0:
flag=0
break
else:
flag=1
if flag==0:
print("False")
else:
print("True")
else:
def print_factors():
num = int(input("Enter a number: "))
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
def palindrome():
n = int(input("Enter a number: "))
s=0
t=n
while t>0:
r=t%10
s=s*10+r
t=t//10
if n==s:
print("Palindrome")
else:
print("Not Palindrome")
def armstrong():
n = int(input("Enter a number"))
order = len(str(n))
sum = 0
temp = n
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if n == sum:
print(n,"is an Armstrong number")
else:
print(n,"is not an Armstrong number")
if __name__=='__main__':
add()
multiply()
factorial()
prime()
print_factors()
palindrome()