0% found this document useful (0 votes)
36 views3 pages

Class 11 - CS - Programs On Ifelse

Uploaded by

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

Class 11 - CS - Programs On Ifelse

Uploaded by

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

Programs on Decision Making Statements

1. Program that takes a number and checks whether the given number is odd or even.
Solution:
num = int(input("Enter any number : "))
if (num % 2) == 0:
print ("The number is even")
else:
print ("The provided number is odd")

Output:
Enter any number : 56
The number is even

2. Program to accept 3 integers and print the largest of the three.


Solution:
a = int(input("Enter the first number : "))
b = int(input("Enter the second number : "))
c = int(input("Enter the third number : "))

if a >= b and a >= c:


max = a
elif b >= a and b >= c:
max = b
else:
max = c

print(max, "is the largest of three numbers.")

Output:
Enter the first number : 56
Enter the second number : 78
Enter the third number : 99
99 is the largest of three numbers.

3. Program that reads two numbers and an arithmetic operator and displays the result.
Solution:
num1= float(input("Enter first number: "))
num2=float(input("Enter second number: "))
op=input("enter operator [+-*/%] ")
result=0
if op=='+':
result=num1+num2
elif op =='-':
result=num1-num2
elif op=='*':
result=num1*num2
elif op=='/':
result=num1/num2
else:
print("Invalid operator!!")
print(num1,op,num2,'=',result)

Output:
Enter first number: 8
Enter second number: 2
enter operator [+-*/%] /
8.0 / 2.0 = 4.0

4. Program to print whether a given character is an uppercase or lowercase or a digit or a


special character.
Solution:
ch = input("Enter a single character : ")
if ch >= 'A' and ch <= 'Z':
print("You have entered an Uppercase character")
elif ch >= 'a' and ch <= 'z':
print("You have entered an Lowecase character")
elif ch >='0' and ch <= '9':
print("You have entered a digit")
else:
print("You have entered a special character")

Output:
Enter a single character : V
You have entered an Uppercase character

5. Write a program to check if a given year is leap year or not.


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

Output:
Enter the year : 2024
2024 is a leap year

6. Write a program to print monthly telephone bill. Calculate the bill based on the following
criteria.

Number of call Price/call


Upto 100 0.00
>100 2.50
>500 4.50
>1000 7.50

If the number of calls is 250 then no charges for first 100 calls and remaining 150 calls will be
charged as 2.50.
Solution:

calls=int(input("Enter number of calls : "))

bill=0

if(calls<=100): # first 100 call free

bill=0

elif (calls>100 and calls<=500): # 100 free after 2.50 rs/call

bill=100*0+(calls-100)*2.50

elif (calls>500 and calls<=1000):

bill=100*0 + 400*2.50 + (calls-500)*4.50

else:

bill=100*0 + 400*2.50 + 500*4.5 + (calls-1000)*7.50

print("Total bill amount is", bill)

Output ->

Enter number of calls : 1200

Total bill amount is 4750.0

You might also like