diff --git a/armstrong.py b/armstrong.py new file mode 100644 index 0000000..8f14991 --- /dev/null +++ b/armstrong.py @@ -0,0 +1,14 @@ +num = int(input("Enter a number: ")) +sum = 0 + +temp = num +while temp > 0: + digit = temp % 10 + sum += digit ** 3 + temp //= 10 + + +if num == sum: + print(num,"is an Armstrong number") +else: + print(num,"is not an Armstrong number") \ No newline at end of file diff --git a/factorial.py b/factorial.py new file mode 100644 index 0000000..c4dc881 --- /dev/null +++ b/factorial.py @@ -0,0 +1,8 @@ +def fact(n): + if n==1: + return 1 + else: + return n*fact(n-1) + +n= int(input("Enter a no:")) +print("Factorial is : ",fact(n)) \ No newline at end of file diff --git a/lcm.py b/lcm.py new file mode 100644 index 0000000..4dbaaa2 --- /dev/null +++ b/lcm.py @@ -0,0 +1,16 @@ +def lcm(x, y): + if x > y: + greater = x + else: + greater = y + + while(True): + if((greater % x == 0) and (greater % y == 0)): + lcm = greater + break + greater += 1 + + return lcm +a=int(input("Enter the first no: ")) +b=int(input("Enter the second no: ")) +print ("Lcm is : ",lcm(a,b)) \ No newline at end of file diff --git a/prime.py b/prime.py new file mode 100644 index 0000000..5751ce4 --- /dev/null +++ b/prime.py @@ -0,0 +1,17 @@ +num = 407 + + + +if num > 1: + + for i in range(2,num): + if (num % i) == 0: + print(num,"is not a prime number") + print(i,"times",num//i,"is",num) + break + else: + print(num,"is a prime number") + + +else: + print(num,"is not a prime number") \ No newline at end of file