Professional Documents
Culture Documents
WORKSHEET – 1.2
Name: Abhishek
Section/Group: 719 /“A”
UID: 20BCS7643
Subject: Programming in Python Lab
Date of Submission:04.03.2022
Branch: BE CSE (4 Semester)
th
Aim:
Write a python code that will implement Conditional Statements and Loop
Control Structure.
Task to be done:
1. Write a program to check whether a given number is a palindrome.
2. Write a program to check whether entered number is Armstrong or not.
3. Write a program to take three numbers from the user and print the
greatest number.
Algorithm / Flowchart:
1. To check that whether the given number is palindrome or not:
Start the program.
Enter the number from the user.
Store the number in a temporary variable.
With the help of while loop get each digit of the number and store
the reversed number in another variable.
Check if the reversed number is equal to the temporary variable or
not.
Print all the values with a suitable message.
End the program.
3. To enter the three numbers from the user and print the greatest
number:
Start the program.
Enter the three numbers from the user.
Check the greatest number using conditional statements.
Print all the values with a suitable message.
End the program.
Code:
1. To check that whether the given number is palindrome or
not:
#Python program to check that whether the given number is palindrome
or not
#Take the number from the user
num=int(input("Enter number:"))
#Store the number in temporary variable
temp=num
rev=0
#Extract the digit of the number and store the reverse of the number
while(num>0):
digit=num%10
rev=rev*10+digit
num=num//10
#Check whether the reverse of the number is equal or not
if(temp==rev):
#Print the message
print(temp,"is a palindrome number")
else:
print(temp,"is not a palindrome number")
3. To enter the three numbers from the user and print the
greatest number:
#Python program to enter the three numbers from the user and print the
greatest number:
#Take three numbers from the user
n1 = int(input("Enter the first number:"))
n2 = int(input("Enter the second number:"))
n3 = int(input("Enter the third number:"))
#Check the greatest number using conditional statements
if(n1 >= n2) and (n1 >= n3):
greatest = n1
elif(n2 >= n1) and (n2 >= n3):
greatest = n2
else:
greatest = n3
#print the result
print("The greatest number among three is",greatest)
Screenshots:
1. To check that whether the given number is palindrome or
not:
#Python program to check that whether the given number is palindrome or not
#Take the number from the user
num=int(input("Enter number:"))
#Store the number in temporary variable
temp=num
rev=0
#Extract the digit of the number and store the reverse of the number
while(num>0):
digit=num%10
rev=rev*10+digit
num=num//10
#Check whether the reverse of the number is equal or not
if(temp==rev):
#Print the message
print(temp,"is a palindrome number")
else:
print(temp,"is not a palindrome number")
3. To enter the three numbers from the user and print the
greatest number:
#Python program to enter the three numbers from the user and print the greatest
number:
#Take three numbers from the user
n1 = int(input("Enter the first number:"))
n2 = int(input("Enter the second number:"))
n3 = int(input("Enter the third number:"))
#Check the greatest number using conditional statements
if(n1 >= n2) and (n1 >= n3):
greatest = n1
elif(n2 >= n1) and (n2 >= n3):
greatest = n2
else:
greatest = n3
#print the result
print("The greatest number among three is",greatest)
Result / Output:
1. To check that whether the given number is palindrome or
not:
3. To enter the three numbers from the user and print the
greatest number:
Learning Outcomes:
1. Learn how to implement the conditional statements and loop control
structures in python.
2. Learn about loop while loop.
3. Learn about conditional statements.
4. Learn about type conversion.
5. Learn how to write code in python , about indentation.