You are on page 1of 5

CLASS 11 Computer Science

Practical Answers
1. Write a program to calculate simple interest.
#To calculate simple interest
p=eval(input('Enter principal amount='))
r=eval(input('Enter interest rate='))
t=eval(input('Enter time='))
si=p*r*t/100
print('Simple Interest=',si)
2. Write a python program to obtain temperature in Celsius and convert it
into Fahrenheit.
#Convert Celsius to Fahrenheit
C=float(input('Enter temperature in Celsius='))
F=C*9/5+32
print('Fahrenheit=',F)
3. Write a python program to check whether the given number is odd or
even.
#Check whether the number is odd or even
num=int(input('Enter a number='))
if num%2==0:
print('Even number')
else:
print('Odd number')
4. Write a python to find the biggest among three numbers.
#Find Largest among three numbers
a=int(input('Enter first number='))
b=int(input('Enter second number='))
c=int(input('Enter third number='))
if a>b and a>c:
print(a,'is the largest number')
elif b>c:
print(b,'is the largest number')
else:
print(c,'is the largest number')
5. Write a python program that reads two numbers and an arithmetic
operator and display the results.
#Arithmetic calculator
a=int(input('Enter first number='))
b=int(input('Enter second number='))
op=input('Enter operator=')
if op=='+':
print(a+b)
elif op=='-':
print(a-b)
elif op=='*':
print(a*b)
elif op=='/':
print(a/b)
elif op=='%':
print(a%b)
elif op=='//':
print(a//b)
elif op=='**':
print(a**b)
else:
print('Invalid operator')

6. Write a python program to get the sales amount and calculate commission
for the salesman (using nested if statement). The commission is
calculated according to following rates:
SALES COMMISSION
RATE
30001 15%
ONWARDS
22001-30000 10%
12001-22000 7%
5001-12000 3%
0-5000 0%
#To calculate commission
s=int(input('Enter sales amount='))
if s>=30001:
c=s*15/100
print('Commission=',c)
elif s>=22001 and s<=30000:
c=s*10/100
print('Commission=',c)
elif s>=12001 and s<=22000:
c=s*7/100
print('Commission=',c)
elif s>=5001 and s<=12000:
c=s*3/100
print('Commission=',c)
elif s>=0 and s<=5000:
c=s*0/100
print('Commission=',c)
7. Write a program to accept a roll number of a student and marks in three
subjects. Calculate grade with the following criteria.
[Average=total marks/no. of subjects]

Average Grade
If average is greater than 80 A
If average is between 60-80 B
If average is between 40-59 C
If average is less than 40 D

#To calculate grade


rollno=int(input('Enter roll number='))
math=int(input('Enter marks in maths='))
science=int(input('Enter marks in science='))
social=int(input('Enter marks in social='))
avg=(math+science+social)/3
if avg>=80:
print('Grade A')
elif avg>=60 and avg<80:
print('Grade B')
elif avg>=40 and avg<60:
print('Grade C')
elif avg<40:
print('Grade D')
8.Write a program to perform the following task according to user’s
choice using menu. (Menu driven program).
a. Find area of square.
b. find area of rectangle.
c. find area of circle.
#Area Calculation
import math
print('1. Find the area of square')
print('2. Find the area of rectangle')
print('3. Find the area of circle')
ch=int(input('Enter your choice='))
if (ch==1):
s=int(input('Enter length of the side='))
a=s*4
print('Area=',a)
elif (ch==2):
l=int(input('Enter length='))
b=int(input('Enter breadth='))
a=l*b
print('Area=',a)
elif (ch==3):
r=int(input('Enter radius='))
a=2*math.pi*r
print('Area=',a)
else:
print('Invalid choice')
9. Write a python program to find whether an inputted number is zero, a
positive number or a negative number.
#Check Positive, negative or zero
num=int(input('Enter a number='))
if num==0:
print('The number is zero')
elif num>0:
print('The number is positive')
else:
print('The number is negative')
10.Write a program to check whether the given character is alphabet or digit.
If the character is alphabet then check whether it is vowel or not.
#check alphabet or digit
ch=input('Enter character=')
if ch>='a' and ch<='z' or ch>='A' and ch<='Z':
print(' The given character is Alphabet')
if ch==’a’ or ch==’e’ or ch==’i’ or ch==’o’ or ch==’u’
or ch==’A’ or ch==’E’ or ch==’I’ or ch==’O’ or ch==’U’:
print(‘The given character is vowel’)
else:
print(‘The given character is not vowel’)
elif ch>='0' and ch<='9':
print(' The given character is Digit')
else:
print('Special character')

You might also like