0% found this document useful (0 votes)
19 views

Python Worksheet 1.2

This worksheet contains programs to check palindromes, Armstrong numbers, and greatest of three numbers. For palindromes, it takes a number as input, reverses it, and checks if it is equal to the original. For Armstrong numbers, it calculates the sum of each digit raised to the power of the number of digits and checks if it is equal to the original number. For greatest number, it takes three numbers as input and compares them to print the largest. Screenshots of outputs are provided for each program.

Uploaded by

Sahil Arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Python Worksheet 1.2

This worksheet contains programs to check palindromes, Armstrong numbers, and greatest of three numbers. For palindromes, it takes a number as input, reverses it, and checks if it is equal to the original. For Armstrong numbers, it calculates the sum of each digit raised to the power of the number of digits and checks if it is equal to the original number. For greatest number, it takes three numbers as input and compares them to print the largest. Screenshots of outputs are provided for each program.

Uploaded by

Sahil Arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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