Python Operators: Arithmetic, Relational, Logical, and Ternary Operators, Assignments of Computer Science

First assignment basics for any non technical students

Typology: Assignments

2020/2021

Uploaded on 10/02/2021

Mukund0210
Mukund0210 🇮🇳

1 document

1 / 15

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
TITLE: Operators (Arithmetic, Relational, Logical and
Ternary operators)
Aim: Understanding the functions of operators in python.
Software Required: IDLE3.9.7 MICROSOFT WORD.
EXERCISE 1:
1. From Standard input, read two integers n1, n2.
Print the following:
a. Sum of two numbers.
b. Multiplication of given two numbers.
c. Quotient 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:
1)TWO NUMBERS
SUM,MULTIPLICATION,
QUOTIENT,REMAINDER,
EXPONENTIAL,FLOOR
DIVISION.
PROCESSING REQUIRED:
ALTERNATE SOLUTION:
1)SUM=N1+N2
-
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Python Operators: Arithmetic, Relational, Logical, and Ternary Operators and more Assignments Computer Science in PDF only on Docsity!

TITLE: Operators (Arithmetic, Relational, Logical and Ternary operators) Aim: Understanding the functions of operators in python. Software Required: IDLE3.9.7 MICROSOFT WORD. EXERCISE 1:

  1. From Standard input, read two integers n1, n2. Print the following: a. Sum of two numbers. b. Multiplication of given two numbers. c. Quotient of n1 and n2. d. Remainder of n1 and n2. e. n1 to the power n. f. floor quotient of n1 and n2. PAC: GIVEN DATA: REQUIRED RESULT: 1)TWO NUMBERS SUM,MULTIPLICATION, QUOTIENT,REMAINDER, EXPONENTIAL,FLOOR DIVISION. PROCESSING REQUIRED: ALTERNATE SOLUTION: 1)SUM=N1+N2 -

2)MULTIPLICATION=N1*

N

3)DIVISION=N1/N

4)REMAINDER=N1%N

5)EXPONENTIAL=N1**N 2

6) FLOOR=N1//N

ALGORITHM:

Step1-start Step2-get the values of a and b Step3-c=a+b Step4-display c Step5- d=ab Step6- display d Step7-e=a/b Step8- display e Step9-f=a%b Step10- display f Step11-g=a*b Step12- display g Step13-h=a//b Step14- display h

power=n1**n floor=n1//n print(sum,mult,div,rem,power,floor) EXERCISE 2:

  1. 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:

GIVEN DATA: REQUIRED RESULT:

1)Initial amount 2)No of Years 3)Expected Matured Amount. Rate of interest PROCESSING REQUIRED: ALTERNATE SOLUTION:

  • Rate of interest = ((expected matured amount-initial amount)/ (initial amount * no of years))*

NONE

ALGORITHM:

Step1: Start Step2: Get the values of a,b and c Step3: Initialize a new variable d Step4: d= ((c-a)/(ab)) Step5: display d CODE: #Print rate of interest a=int(input("Initial amount"))

GIVEN DATA: REQUIRED RESULT:

Items Quantity Price Total Amount PROCESSING REQUIRED: ALTERNATE SOLUTION: Total Cost:Addition of(price of item * quantity of item) None ALGORITHM: Step1:Start Step2:Get the Values of q1,q2,q3andp1,p2,p3. Step3:Total=(q1p1)+(q2p2)+(q3*p3) Step4:Display Total. Code: q1=int(input("Enter the quantity of bread bought")) p1=float(input("Enter the price")) q2=int(input("Enter the quantity of butter bought")) p2=float(input("Enter the price"))

q3=int(input("Enter the quantity of jam bought")) p3=float(input("Enter the price")) tot_price=q1p1+q2p2+q3*p print("Total amount to pay:",tot_price) EXERCISE 4:

  1. An 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 Labour cost = number of hours worked
  • wages per hour. PAC: GIVEN DATA: REQUIRED RESULT:

p2=float(input("Enter the price of table")) n3=int(input("Enter the number of chairs")) p3=float(input("Enter the price of chair")) n4=int(input("Enter the number of hours worked by one laborer")) p4=p3=float(input("Enter the wage")) tot_price=n1p1+n2p2+n3p3+n4p4#costs of computer,chairs,table and laborer print("Total amount to pay:",tot_price) EXERCISE 5: Evaluate the following arithmetic operations.

  1. 5%10+10<50 and 29>=
  2. 7**2<=5//9%3 or 'bye'<'Bye'
  1. 5%10<10 and - 25>1*8//
  2. 7**2//4+5>8 or 5!=
  3. 7/4<6 and'I am fine'>'I am not fine'
  4. 10+62*2!=9//4-3 and 29>=29/
  5. 'hello'5>'hello' or 'bye'<'Bye' Code: =5%10+10<50 and 29>= print(a) b=72<=5//9%3 or 'bye'<'Bye' print(b) c=5%10<10 and - 25>18// print(c) d=72//4+5>8 or 5!= print(d) e=7/4<6 and'I am fine'>'I am not fine' print(e) f=10+622!=9//4-3 and 29>=29/ print(f) g='hello'5>'hello' or 'bye'<'Bye' print(g)

Output:

Output: 5.Syntax for tuple. Output:

6.syntax for list Output: 7.Syntax for Dictionary. Output: INFERENCE: Understandood the functions of operators in python.