I037 - Manas Patel Experiment02

You might also like

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

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III

PRACTICAL 2

Problem Statement: Write Python program to


1. Accept three sides of a triangle and print if the triangle is equilateral, isosceles or
scalene.
2. A function f is defined as follows :
f(x) = ax3 – bx2 + cx –d, if x > k
= 0, if x = k
= -ax3 + bx2 – cx +d, if x < k
Write a program that reads a, b, c, d, k and x and prints the value of f(x).
3. Create a calculator.
4. A cloth showroom has announced the following discounts on the purchase of specific
items:
Amount Shorts Pants Shits/T-Shirts

0-100 – 3% 5%

101-200 5% 8% 10%

201-300 10% 12% 15%

Above 300 18% 20% 22%


Ask user to enter the amount and assign following code for the items such as s for
shorts, p for pans and t for shirts/t-shirts.
Compute the discount and net amount paid by customer.

PRACTICAL 2

Conditional Statements (if, if…else, nested if)


Roll No.: I037 Name: Manas Hiteshbhai Patel
Prog/Yr/Sem: MBA Tech. IT 2nd Yr Sem-III Batch: A2
Date of Experiment: 29-07-2022 Date of Submission:

1. Questions based on Experiment Scenario:


a. Describe the syntax and describe conditional statements with example.
Ans. The syntax is set of rules that defines how a program will be written and interpreted.
The conditional statement is to make decision based on certain conditions. Conditions are
set of statements having Boolean expression true or false.

1|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III
Types of conditional statements are if statements, if-else statement, elif statement, nested-
if-else statement and elif ladder.
For example:
CODE: OUTPUT:
num = 5
if (num < 10): Num is smaller than 10
print(“Num is smaller than 10”)
else:
print(“This statement will always be
executed”)
In this code, number 5 is stored in variable num and then num is passed in if-else
statement and if num is less than 10 then it will print “Num is smaller then 10” and if not
then else statement will be executed.

b. Multiple Choice

1. Can we write if/else into one line in python?


a. i = 2 if a > 5 else 0
b. No
a. i = 2 if a > 5 else 0
c. if a > 5: i=2 else 0
d. None of the above

2. Which one of the following is a valid Python if statement.


a. if a>=2 :
b. if (a >= 2)
If a>=2 :
c. if (a => 22)
d. if a >= 22

3. What is the output of the given below program?


if 1 + 3 == 7:
print("Hello")
else:
print("Know Program")
a. Hello b. Know Program
b. Know Program
c. Compiled Successfully, No Output.
d. Error

2|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III

4. Find the output of the given Python program?


a, b, c = 1, 3, 5
if a > 0:
if b < 2:
print("Hi")
elif c > 3:
print("Hello")
b. Hello
else:
print("Know Program")
a. Hi
b. Hello
c. Know Program
d. Compiled Successfully, No Output.

5. Find the output of the given Python program?


a = 25
if a > 15:
print("Hi")
if a <= 30:
print("Hello")
else: c. Hi
print("Know Program") Hello
a. Hi
b. Hello
c. Hi
Hello
d. Hi
Know Program

2. Program Code along with Sample Output:

1. CODE:
#Triangle Equilateral OR Isoceles OR Scalene

s1=int(input("Enter side 1 of triangle:"))


s2=int(input("Enter side 2 of triangle:"))
s3=int(input("Enter side 3 of triangle:"))

if (s1==s2==s3):

3|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III

print("Equilateral Triangle")
elif ((s1==s2)or(s2==s3)or(s1==s3)):
print("Isosceles Triangle")
else:
print("Scalene Triangle")

OUTPUT:

2. CODE:
#Function and print f(x)

import math
#from math import pow

a=int(input("Enter value of a:"))


b=int(input("Enter value of b:"))
c=int(input("Enter value of c:"))
d=int(input("Enter value of d:"))
k=int(input("Enter value of k:"))

4|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III

x=int(input("Enter value of x:"))

if (x>k):
f=(a*(x**3))-(b*(x**2))+(c*x)-d
print("x is more than k")
elif (x==k):
f=0
print("x is equal to k")
else:
f=-a*math.pow(x,3)+b*math.pow(x,2)-(c*x)+d #a*pow(a1,b1)
print("x is less than k")

print("The value of f(x) is ",f)

OUTPUT:

5|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III

3. CODE:
#Calculator

num1=int(input("Enter number 1:"))


num2=int(input("Enter number 2:"))
op=input("Enter operator:")

if (op=="+"):
print("The sum of numbers is ",num1+num2)
elif (op=="-"):
print("The difference of numbers is ",num1-num2)
elif (op=="*"):
print("The product of numbers is ",num1*num2)
elif (op=="/"):
if (num2==0):
print("Division Not Possible")
else:
print("The division of numbers is ",num1/num2)
elif (op=="%"):
print("The modulus of numbers is ",num1%num2)
else:
print("Invalid Input")

OUTPUT:

6|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III

4. CODE:
#Bill Amount and Discounts

amt=int(input("Enter the bill amount:"))


item=input("Enter item (s-shorts p-pants t-shirts/t-shirts): ")

if (amt>=0 and amt<=100):


print("Amount:",amt)
if (item=="s"):
net_amt=amt;
elif (item=="p"):
net_amt=amt-(amt*0.03);
elif (item=="t"):
net_amt=amt-(amt*0.05);
elif (amt>=101 and amt<=200):
print("Amount:",amt)
if (item=="s"):
net_amt=amt-(amt*0.05);
elif (item=="p"):
net_amt=amt-(amt*0.08);
elif (item=="t"):
net_amt=amt-(amt*0.1);
elif (amt>=201 and amt<=300):
print("Amount:",amt)
if (item=="s"):
net_amt=amt-(amt*0.1);
elif (item=="p"):
net_amt=amt-(amt*0.12);
elif (item=="t"):

7|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering

Course: Python Programming


PROGRAMME: B.(Tech.) Computer Science and Engineering (Cybersecurity),
MBA(Tech.) IT
Second Year AY 2022-2023 Semester: III

net_amt=amt-(amt*0.15);
else:
print("Amount:",amt)
if (item=="s"):
net_amt=amt-(amt*0.18);
elif (item=="p"):
net_amt=amt-(amt*0.2);
elif (item=="t"):
net_amt=amt-(amt*0.22);

print("Net Amount:",net_amt)

OUTPUT:

3. Conclusion (Learning Outcomes): The learnings after the practical is about the
conditional looping statement which includes if-statement, if-elif statement and elif ladder
which is helpful in making decision-based syntax for user.

8|Page

You might also like