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

If - Else - Worksheet (Class 11)

Uploaded by

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

If - Else - Worksheet (Class 11)

Uploaded by

syashveer127
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Program Worksheet

Chapter –Flow of control


Class – XI

1. Write a Python program to find maximum between two numbers.

n1=int(input('Enter the first number :'))


n2=int(input('Enter the second number :'))
if(n1>n2):
print(n1, "is greater than ",n2)
else:
print(n2, "is greater than ",n1)
Or
##Write a Python program to find maximum between two numbers.
n1=int(input('Enter the first number :'))
n2=int(input('Enter the second number :'))
if(n1==n2):
print("Both are equal.")
elif(n1>n2):
print(n1, "is greater than ",n2)
else:
print(n2, "is greater than ",n1)

2. Write a Python program to find maximum between three numbers.

a=int(input('Enter the first number :'))


b=int(input('Enter the second number :'))
c=int(input('Enter the third number :'))
if(a==b==c):
print('These are equal.')
elif(a>b>c):
print(a, ' is the biggest number.')
elif(b>a>c):
print(b, ' is the biggest number.')
else:
print(c, ' is the biggest number.')

3. Write a Python program to check whether a number is negative, positive or zero.

num=int(input('Enter the number :'))


if(num==0):
print('It is zero.')
elif(num>0):
print('It is positive.')
else:
print('It is negative.')

4. Write a Python program to check whether a number is divisible by 5 and 11 or not.

num=int(input('Enter the number :'))


if(num%5==0 and num%11==0):
print('It is divisible by 5 and 11')
else:
print('It is not divisible by 5 and 11')
5. Write a Python program to check whether a number is even or odd.

num=int(input('Enter the number :'))


if(num%2==0):
print(num, ' is even number')
else:
print(num, ' is odd number')

6. Write a Python program to check whether a year is leap year or not.

year = int(input("Enter a year: "))


if (year % 4) == 0 and
if (year % 100) == 0:
if (year % 400) == 0:
print(year , “ is a leap year")
else:
print(year , “ is not a leap year")
else:
print(year , “ is a leap year")
else:
print(year , “ is not a leap year")
OR
year = int(input("Enter Year: "))
if (year % 4 == 0 and year % 100 != 0):
print(year, "is a Leap Year")
elif (year % 100 == 0):
print(year, "is not a Leap Year")
elif (year % 400 ==0):
print(year, "is a Leap Year")
else:
print(year, "is not a Leap Year")

7. Write a Python program to check whether a character is alphabet or not.

ch = input("Please Enter Your Own Character : ")

if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
elif(ch >= '0' and ch <= '9'):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is Not an Alphabet or a Digit")

OR

ch=input("Please enter the character as you wish")


if((ord(ch)>=65 and ord(ch)<=90)or(ord(ch)>=97 and ord(ch)<=122)):
print(ch," is an Alphabet: ");
else:
print(ch," is not an Alphabet: ")
else:
print("The Given Character ", ch, "is Not an Alphabet or a Digit")
OR
ch=input("Please enter the character as you wish")
if((ord(ch)>=65 and ord(ch)<=90)or(ord(ch)>=97 and ord(ch)<=122)):
print(ch," is an Alphabet: ");
else:
print(ch," is not an Alphabet: ")

8. Write a program to input the cost price and the selling price of an article. If
the selling price is more than the cost price then calculate and display actual
profit and profit per cent otherwise, calculate and display actual loss and loss
per cent. If the cost price and the selling price are equal, the program displays
the message 'Neither profit nor loss'.

cp =float(input("Enter cost price of the article: "))


sp =float(input("Enter selling price of the article: "))
pl = sp - cp
percent = pl / cp * 100
if (pl > 0):
print("Profit = " , pl)
print("Profit % = " , percent)
elif(pl < 0):
print("Loss = " , pl)
print("Loss % = " , percent)
else:
print("Neither profit nor loss")

9. Without using if-else statement and ternary operators, accept three unequal
numbers and display the second smallest number.

print("Enter 3 unequal numbers")


a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))
sum = a + b + c;
big = max(a, b);
big = max(big, c);
small = min(a, b);
small = min(small, c);
result = sum - big - small;
print("Second Smallest Number = " ,result)

10. A Pre-Paid taxi charges from the passenger as per the tariff given below:

Distance Rate
Up to 5 km ₹ 100
For the next 10 km ₹ 10/km
For the next 10 km ₹ 8/km
More than 25 km ₹ 5/km
Write a program to input the distance covered and calculate the amount paid by
the passenger. The program displays the printed bill with the details given
below:
Taxi No. :
Distance covered :
Amount :

taxiNo=input("Enter Taxi Number: ")


dist=int(input("Enter distance travelled: "))
fare = 0
if (dist <= 5):
fare = 100
elif (dist <= 15):
fare = 100 + (dist - 5) * 10
elif (dist <= 25):
fare = 100 + 100 + (dist - 15) * 8
else:
fare = 100 + 100 + 80 + (dist - 25) * 5
print("Taxi No: " , taxiNo)
print("Distance covered: " , dist)
print("Amount: " , fare)

11. A cloth showroom has announced festival discounts and the gifts on the
purchase of items, based on the total cost as given below:
Total Cost Discount Gift
Up to ₹ 2,000 5% Calculator
₹ 2,001 to ₹ 5,000 10% School Bag
₹ 5,001 to ₹ 10,000 15% Wall Clock
Above ₹ 10,000 20% Wrist Watch
Write a program to input the total cost. Compute and display the amount to be
paid by the customer along with the gift.

cost=float(input("Enter total cost: "))


gift=0;amt=0
if(cost <= 2000.0):
amt = cost - (cost * 5 / 100)
gift = "Calculator"
elif (cost <= 5000.0):
amt = cost - (cost * 10 / 100)
gift = "School Bag"
elif (cost <= 10000.0):
amt = cost - (cost * 15 / 100)
gift = "Wall Clock"
else:
amt = cost - (cost * 20 / 100)
gift = "Wrist Watch"
print("Amount to be paid: ", amt)
print("Gift: " , gift)

You might also like