Class 11 - CS - Programs On Ifelse
Class 11 - CS - Programs On Ifelse
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
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
Output:
Enter a single character : V
You have entered an Uppercase character
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.
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:
bill=0
bill=0
bill=100*0+(calls-100)*2.50
else:
Output ->