You are on page 1of 3

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET 1.2

Student Name: Vishesh Pratap Singh UID: 21BCS2233


Branch: CSE Section/Group: 21BCS619-A
Semester:4 Date of Performance:15.02.2023
Subject Code: 21CSP-259
Subject Name: Programming in Python Lab

1. Aim:
1. Write a Python Program to check whether a given number is a
palindrome.
2. Write a Python Program to check Whether entered number is
Armstrong or Not?
3. Write a Python Program to Take three numbers from the user and
print the greatest number

2. Source Code:

1. Palindrome

num = int(input("Enter a number: "))


reverse_num = str(num)[::-1]

if str(num) == reverse_num:
print(num, "is a palindrome")
else:
print(num, "is not a palindrome")

2. Armstrong

num = int(input("Enter a number: "))


sum = 0
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

n = len(str(num))

temp = num
while temp > 0:
digit = temp % 10
sum += digit ** n
temp //= 10

if num == sum:
print(num, "is an Armstrong number")
else:
print(num, "is not an Armstrong number")

3. Greatest number

a=int(input("Enter 1st number: "))


b=int(input("Enter 2nd number: "))
c=int(input("Enter 3rd number: "))

print(a,b,c)

if a>b and a>c:


print(a,"is greater")
elif b>a and b>c:
print(b,"is greater")
else:
print(c,"is greater")

3. Screenshot of Outputs:

1. Palindrome
2. Armstrong

3. Greatest

You might also like