Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

LAB MST

NAME – AJAY SAINI UID -20BCS9523


SEMESTER-1ST SUBJECT- PROGRAMMING IN PYTHON
SECTION/GROUP- 813/B BRANCH – BE_CSE

QUESTION 1. Write a python program to determine the number is armstrong or polindrome number where the
number is passed as argument to a function.

Code-
num = int(input("Enter a number : "))
def armstrong(num):
    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")     
def palindrome(num):
    temp = num
    rev = 0
    while (num > 0):
        d = num % 10
        rev = rev *10 + d
        num = num//10
    if temp == rev :
        print( temp,"is palindrome number")
    else :
        print( temp, "is not palindrome number")

armstrong(num)
palindrome(num)

Output-
Question 2- Write a Python program to find Length of String without using inbuilt Function.
Code-
string=input("Enter a string : ")

def length(string):
    stringLength=0
    for i in string:
        stringLength=stringLength+1
    return stringLength

print(length(string))
Output-

You might also like