Type C: Programming Practice /Knowledge based Questions
Informatics Practices – Pg 77,78
1. Write a program that displays a joke. But display the punchline only when the user presses enter key.(Hint
You may use input())
print("this is a joke")
print("Press enter")
a =input()
print("Happy Diwali")
2. Write a program to read today’s date (only del part from user. Then display how many days are left in the
current month.
date =int(input("Enter todays date:"))
month=int(input("Enter number of days in this month:"))
rem=month-date
print("Remaining days of this month are:",rem)
3. Write a program that generates the following output : 5
10
9
Assign value 5 to a variable using assignment operator (=) .Multiply it with 2 to generate 10 and subtract 1
to generate 9.
a=5
print(a)
print(a*2)
print(a*2-1)
4. Modify the above program so as to print output as 5@10@9
print(a,end="@")
print(a*2,end="@")
print(a*2-1)
OR
print(a,a*2,a*2-1,sep="@")
5. Write the program with maximum three lines of code that assigns first 5 multiples of a number to 5
variables and then print them.
num=int(input("Enter a number:"))
a,b,c,d,e=num*1,num*2,num*3,num*4,num*5
print(a,b,c,d,e)
6. Write a Python program that accepts radius of a circle and prints its area.
r=int(input("Enter the radius of a circle:"))
area = 3.14*r*r
print("Area of circle with radius",r,"is",area)
7. Write a Python program that accepts marks of 5 subjects and outputs average marks.
sub1=int(input("Enter the marks scored in first subject:"))
sub2=int(input("Enter the marks scored in second subject:"))
sub3=int(input("Enter the marks scored in third subject:"))
sub4=int(input("Enter the marks scored in fourth subject:"))
sub5=int(input("Enter the marks scored in fifth subject:"))
avg=(sub1+sub2+sub3+sub4+sub5)/5
print("Your average of 5 subject is",avg)
8. Write a short program that asks for your height in centimetres and then converts your height to feet and
inches.(1 foot = 12 inches, 1 inch =2.54 cm)
ht_centi=float(input("enter your height in centimeters:"))
ht_inch=ht_centi/2.54
ht_feet=ht_inch/12
print("Your height in inches is:",ht_inch)
print("Your height in feet is:",ht_feet)
9. Write a program to read a number n and print n2,n3 and n4.
n=int(input("Enter a number:"))
n2=n**2
n3=n**3
n4=n**4
print("Number raise to the power 2 is:",n2)
print("Number raise to the power 3 is:",n3)
print("Number raise to the power 4 is:",n4)
10. Write a program to find area of a triangle.
#Area of Triangle
base=int(input("Enter the base of triangle:"))
height=int(input("Enter the height of triangle:"))
area= 1/2*(base*height)
print("Area of triangle is:",area)
11. Write a program to compute simple interest and compound interest.
p=float(input("Enter the principal amount:"))
r=float(input("Enter the rate of interest:"))
t=float(input("Enter time period:"))
si=(p*r*t)/100
ci= (p*(1+r/100)**t)-p
print("The simple interest is:",si)
print("The compund interest is:",ci)
12. Write a program to input a number and print its first five multiples.
num=int(input("Enter a number:"))
print(num,"*","1","=",num*1,'\n',num,"*","2","=",num*2,'\n',num,"*","3","=",num*3,'\n',
num,"*","4","=",num*4,'\n',num,"*","5","=",num*5)
13. Write a program to read details like name, class, age of a student and then print the details firstly in same
line and then in separate lines. Make sure to have two blank lines in these two different types of prints.
name=input("Enter your name:")
clas= input("Enter your class in Roman number:")
age=int(input("Enter your age:"))
print("Your name is:",name,"You are in",clas,"Std","Your age is:",age)
print()
print()
print("Your name is:",name)
print("You are in",clas,"Std")
print("Your age is:",age)
14. Write a program to read three numbers in three variables and swap first two variables with the sums of
first and second , second and third numbers respectively.
num1=int(input("Enter first number:"))
num2=int(input("Enter second number:"))
num3=int(input("Enter third number:"))
num1=num1+num2
num2=num2+num3
print("The swapped values are:",num1,num2,num3)
15. Write a program to input the cost price, selling price and print the profit earned.
cp = int(input("Enter cost price:" ))
sp = int(input("Enter selling price:" ))
profit = sp-cp
print("The profit earned is ","₹",profit)
16. Write a program to input the total liabilities and shareholders’ equity of a company and print its D/E ratio as
Total liabilities / Total Shareholders’ Equity
tl = int(input("Enter Total liabilities:" ))
tse = int(input("Enter Total Sharehlders equity:" ))
de_ratio = tl/tse
print("The D/E ratio is ",de_ratio)
17. Write a program to input a company’s total assets and total equity and print its equity multiplier as Total
Assets / Total Equity
ta = int(input("Enter Companies total assets :" ))
te = int(input("Enter Total equity:" ))
em = ta/te
print("The companies equity multiplier is ",em)
18. Write a program that accepts cost of goods sold (cgos) revenue generated , operating codts(oc) and prints
Gross profit, net profit and net profit percentage.
Net profit= Revenue – cgos-oc
# Code
cgos = int(input('Enter cost of goods sold : '))
rg = int(input('Enter revenue generated : '))
oc = int(input('Enter operating cost : '))
gp = rg - cogs # Gross profit
np = gp - oc # Net profit
npp = np/rg*100 # Net profit percentage
print('Gross profit is', gp)
print('Net profit is', np)
print('Net profit percentage is', npp)