Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

SCHOOL OF INFORMATION TECHNOLOGY AND ENGINEERING

Name:- Chaitanya Goenka

Roll Number:- 21BIT0071

Course code:- BCSE101E

Course Title:- Computer Programming: PYTHON

Module -1
Problem Analysis Chart (PAC):
1. Write a PAC that inputs total capital and total liabilities and prints total
assets. assets=liabilities +capital, assets can also be calculated as
(alternate solutions) assets= 2*liabilities (or) assets =2*capital.

Solution:

Data Processing Output Solution


Alternatives
Liabilities, Assets= Assets Assets= 2×
Capital Liabilities+ Capital
Capital Assets= 2×
Liabilities

2. Write an algorithm that takes sales for four quarters and then displays
total sales and average sales made.
Solution:
Step1: Read sales for four quarters (q1, q2, q3, q4)
Step 2: Compute the sum of q1, q2, q3 and q4
Step 3: Store this result in variable total_sales
Step 4: Print the value of total_sales
Step 5: Divide total_sales by 4
Step 6: Store the result in variable average_sales
Step 7: Print the value of average_sales
Step 8: End the program

3. Draw a flowchart to calculate the net salary after inputting basic salary,
hra%, da% and tax%. Net=basic+hra+da-tax.

Solution:

START

Read basic salary


tax%,da%,hra%

tax %
Tax= 100 × basic

da %
Da= 100 ×basic

hra %
Hra= 100 ×basic

Net=basic+tra+da+hra-tax

Print net
salary

END
4. Write a pseudocode to obtain principal amount, rate of interest and
time from the user and compute simple interest.
Solution:
 Begin
 Numeric rate, time, PA. SI, A
 Display “Enter the rate of interest: ”
 Accept rate
 Display “Enter time period: ”
 Accept time
 Display “Enter principal amount: ”
 Accept PA
 Compute SI= PA*rate*time
 Compute A= P+SI
 Display “The simple interest is:” SI “and the final amount is: ”A
 End
MODULE- 2
5. What is the output produced by following code ? a,b=bool(0),bool(0.0)
c,d=str(0),str(0.0) print(len(a),len(b)) print(len(c),len(d))?
Solution: A TypeError will be shown as bool does not have any length.

6. Predict the output if e is given input as ‘True’


a= True
b=0<5
print(a==b)
print(a is b)
c=str(a)
d=str(b)
print(c==d)
print(c is d)
e= input(“Enter:”)
print(c==e)
print(c is e)
Solution: When this code is executed, we get the output as:
True
True
True
True
Enter: True
True
False

7. Which of the following expressions will result in an error message ( and


why?) being displayed when a program containing it is run?
a. 2.0/4
b. “3”+”Hello”
c. 4%15
d. float(“6”/”12”)
e. int(“5”)/float(“3”)
Solution: float(‘6’/’12’) will show an error because 2 strings cannot be
divided. The ‘/’ can be used only for numeric data type.
8. Write a program that reads a number of seconds and print it in the form:
mins and seconds, eg., 200 seconds are printed as 3 mins and 20
seconds.
Solution: The code: t = int(input("Enter number of seconds: " ))
m = t%60
s= t//60
print("The final result will be" , s , "mins" , m ,"seconds")
9. Write a program to calculate EMI as per the formula: E=PR(1+R)^n
/((1+R)^n -1)
Solution: P = float(input("Enter the principal amount" ))
r = float(input("Enter the interest rate per annum" ))
N = float(input("Enter the number of monthly installments" ))
R = r/(12*100)
print("The monthly interest rate is " , R)
EMI = ((P*R)*(1+R)**N/((1+R)**N-1))
print("The EMI amount is" , EMI)

10.Write a program to take two inputs for day and month and then
calculate which day of the year the given date is. For simplicity, take 30
days for all months. For example, if you give input as Day 3 and month 2,
then it should print “Day of the year:33”. Use a function to perform the
calculation.
Solution: def day_of_year():
M = int(input("Enter the month number"))
D = int(input("Enter the day number"))
DY = (M - 1) * 30 + D
print("Day of the year", DY)
day_of_year()

You might also like