0% found this document useful (0 votes)
19 views8 pages

Python 1.2 KushagrJain

The document contains source code for 10 Python programs demonstrating the use of various control flow statements like if, else if, for, while, break, continue statements. The programs include examples to check if two numbers or strings are equal, check salary range, print a string multiple times in a loop, find the greatest of three numbers, check if a number is Armstrong or palindrome. Each example provides the source code and expected output.

Uploaded by

KUSHnot2OP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views8 pages

Python 1.2 KushagrJain

The document contains source code for 10 Python programs demonstrating the use of various control flow statements like if, else if, for, while, break, continue statements. The programs include examples to check if two numbers or strings are equal, check salary range, print a string multiple times in a loop, find the greatest of three numbers, check if a number is Armstrong or palindrome. Each example provides the source code and expected output.

Uploaded by

KUSHnot2OP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

WORKSHEET- 1.2

Student Name: Kushagr Jain UID:21BCS1877


Branch: CSE Section/Group:615-B
Semester:4th
Subject Name: Programming Subject Code:
in Python Lab 21CSP-259

Aim: Write a Python program to demonstrate the use of following :

2.1 -Write a program to demonstrate if statements.

Source Code:

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


b=int(input("Enter the 2nd number :"))
if a==b:
print("a is equal to b")
if a<b:
print("a is less than b")
if(a>b):
print("a is greater than b")

OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2.2 -Write a program to demonstrate if-else statements.

Source Code:

a=input("Enter the first string :")


b=input("Enter the second string :")
if a==b:
print("Strings are equal")
else:
print("Strings are not Equal")

OUTPUT:

2.3 -Write a program to demonstrate elseif statements.

Source Code:
a=int(input("Enter the Salary :"))
if a<=20000:
print("PA")
elif a>20000 and a<=50000:
print("Staff")
elif a>50000 and a<=100000:
print("Clerk")
elif a>100000:
print("Manager")
else:
print("Default value entered")
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

OUTPUT:

2.4 -Write a program to demonstrate for statements.

Source Code:

a=input("Enter the String :")


b=int(input("Enter the times loop to be executed :"))
for i in range(0,b):
print(a)

OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2.5 -Write a program to demonstrate while statements.

Source Code:

a=input("Enter the String :")


b=int(input("Enter the number of times loop to be executed :"))
i=0
while i<b:
i+=1
print(a)

OUTPUT:

2.6 -Write a program to demonstrate break statements.


Source Code:
a=int(input("Enter the starting range of naturals number :"))
b=int(input("Enter the last range of naturals number :"))
for i in range(a,b):
if i%5==0:
print(i)
break
else:
i+=1
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

OUTPUT:

2.7 -Write a program to demonstrate continue statements.


Source Code:
n=int(input("Enter the limit in which odd numbers to be printed :"))
i=0
while i<n:
i += 1
if (i % 2) == 0:
continue

print(i)

OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2.8 -Write a program to check whether a given number is Armstrong number


or not.

Source Code:

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

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")

OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2.9 -Write a program to check whether a given number is Palindrome number


or not.

Source Code:

n=int(input("Enter the number to be checked for palindrome number :"))


a=n
rev=0
while(n>0):
d=n%10
rev=rev*10+d
n=n//10
if(a==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")

OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2.10 -Write a program to find greater of the given three numbers.

Source Code:

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


b=int(input("Enter the 2nd number :"))
c=int(input("Enter the 3rd number :"))
print("The greatest of Given number is -")
if a>b:
if a>c:
print(a)
else:
print(c)
else:
if b>c:
print(b)
else:
print(c)

You might also like