0% found this document useful (0 votes)
10 views11 pages

Ips1 (Cse)

Uploaded by

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

Ips1 (Cse)

Uploaded by

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

Name:- Tanmay Vikas Admuthe Reg.

No:-21BLC1206

Aim: Understanding different arithmetic, relational, logical and ternary operators.


Software required: Python IDLE, MS WORD
Question 1: From Standard input, read two integers n1, n2.
Print the following:
a. Sum of two numbers
b. Multiplication of given two numbers
c. Tr of n1 and n2.
d. Remainder of n1 and n2
e. n1 to the power n2
f. floor quotient of n1 and n2
PAC:
Given Data Required Result

Two integers’ n1 and n2. Sum


Multiplication
Quotient
Remainder
Power
Floor quotient

Processing Required Alternate Solutions

n1+n2
n1*n2
n1/n2
n1%n2
n1**n2
n1//n2
Algorithm:
Step1. Start
Step2. Input value of n1 and n2
Step3. Sum= n1+n2
Division=n1*n2
Remainder=n1%n2
Power=n1**n2
Floor Division=n1//n2
Step4. Display sum, multiplication, division, remainder, power, floor division.
Step5. Stop

Python Code:

Output:
Question 2: Raman, a finance consultant decides to create a software application
for the public to make decision on the type of investment that they can make. The
input for the software application is the money in hand and the expected matured
amount after ‘n’ years. Write an algorithm and write the Python code to
determine the minimum rate of interest of policy that people may invest to get
the expected maturity amount. Formula to be used is:
* Rate of interest = ((expected matured amount-initial amount)/ (initial amount *
no of years))*100
* Print only two decimal places for rate of interest.

PAC Chart:
Given Data Required Result
1)Initial Amount
2)No. of years Rate Interest
3)Expected Matured amount

Processing Required Alternative Solutions


((Expected Matured Amount-Initial
Amount)/(Initial Amount*No. of years)

Algorithm:
Step1. Start
Step2. Input values a, b, c
Step3. Initialize new variable d
Step4. d=((c-a)/(a*b))*100
Step5. Display d
Step6. Stop

Python Code:
Output:

Question 3: Bob went to a supermarket to buy some items. The items he bought,
its quantity and the price is listed in the following table.
Item Quantity Price per
item
Bread 2 30
Butter 3 25
Jam 3 50
Write PAC, algorithm and python Code to calculate total amount Bob has to pay
to super market.
PAC Chart:
Given Data Required result

Items Total price


Quantity
Price

Processing required Alternate solutions

Total amount=addition of(price of


item*quantity of each item)

Algorithm:
Step1. Start

Step2. Input values of items and there prices.

Step3. Total price= (a*b) + (c*d) + (e*f)

Step4. Display Total price

Step5. Stop

Python Code:
Output:

Question4:
A university is setting up a new lab at their premises. Design an algorithm and
write Python code to determine the approximate cost to be spent for setting up
the lab. Cost for setting the lab is sum of cost of computers, cost of furniture's and
labor cost. Use the following formulae for solving the problem:
Cost of computer = cost of one computer * number of computers, Cost of
furniture = Number of tables * cost of one table + number of chairs * cost of one
chair, Labor cost = number of hours worked * wages per hour

PAC Chart:
Given Data Required results

1. Cost of item Total Cost


2. Price of item
3. Hours worked by the labourers
4. Wage per hour
Processing Required Alternate solutions

Cost of each item= number of item*price


Total cost= summation of all costs of item.

Algorithm:
Step1. Start
Step2. Input values of n1, n2, n3, n4, p1, p2, p3, p4
Step3. Total price= (n1*p1) + (n2*p2) + (n3*p3) + (n4*p4)
Step4. Print total price
Step5. Stop

Python Code:
Output:

Question5: Evaluate the following operations:


1. 5%10+10<50 and 29>=29
2. 7**2<=5//9%3 or 'bye' < 'Bye'
3. 5%10<10 and -25>1*8//5
4. 7**2//4+5>8 or 5!=6
5. 7/4<6 and 'I am fine' > 'I am not fine'
6. 10+6*2**2!=9//4-3 and 29>=29/9
7. 'hello'*5> 'hello' or 'bye' < 'Bye'

Python Code:

Output:

Question6: Ternary operators.


Example 1:
Conditional expression is a Boolean value.

Output:

Code:

Output:

Example 2:

Conditional expression is a Boolean expression.

Output:

Code:

Output:

Ternary operation using a Tuple:


Output:

Ternary operation using List:

Output:

Ternary operation using Dictionary:

Output:

Inference: The above questions and examples helped us understand the use
of Arithmatic, Relational, Logical and Ternary operators.

You might also like