Uploaded by Rohit Jangra

Shivam Bansal py 1.2

advertisement
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
WORKSHEET 1.2
Student Name: Shivam Bansal
Branch: CSE
Date of Performance:24/02/2023
Subject Name: Programming in Python Lab
UID: 21BCS10179
Section/Group:803-A
Subject Code:21-CSP-259
1. Aim:
1. Write a program to check given number is palindrome.
2. Write a program to check whether entered number is an Armstong number.
3. Write a program to take 3 numbers from the user and print the greatest number.
2. Source Code:
1. # Program to check given number is palindrome.
num = int(input("Enter any number: "))
num = str(num) if num[::-1]==num:
print("{} Number is palindrme".format(num)) else:
print("{} Number is not palindrme".format(num))
Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
2. # Program to check whether entered number is an Armstong number.
num = int(input("Enter any number: "))
temp=num
armstrong = 0 while
temp>0: digit =
temp%10
armstrong+=digit**3
temp//=10
if armstrong==num:
print("Number is a Armstrong number!")
Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
3. # program to take 3 numbers from the user and print the greatest number.
x = int(input("Enter x: ")) y
= int(input("Enter y: "))
z = int(input("Enter z: "))
if x>y and x>z:
print(f"x->{x} is the greatest.") elif
y>x and y>z:
print(f"y->{y} is the greatest.")
else: print(f"z->{z} is the
greatest.")
Screenshot of Outputs:
Download