You are on page 1of 10

ASSIGNMENT NO 3

ASSIGNMENT NO 3
Topic:
Python programs
Name:
UMER MUSTAFA
SECTION:
BCS-SP21-004
SUBMITTED TO:
Mam beenish Noor
QUESTION N0 1:
Draw flow chart and write python code for the following.

a) Write a python program to read 3 numbers from user. Use conditional


statements to sort these numbers.
b) Write a Python program to check a triangle is equilateral, isosceles or scalene.

ANSWER:
Using Condition sort out the program:

PROGRAM:
# Get user input
X = int(input("Enter the first number: "))
Y = int(input("Enter the second number: "))
Z = int(input("Enter the third number: "))
small=0
middle=0
large=0
if X<Y and X<Z:
small=X
elif Y<X and Y<Z:
small=Y
elif Z<X and Z<Y:
small=Z
else:
print(" Dont repeat the numbers")
if X>Y and X>Z:
large=X
elif Y>X and Y>Z:
large=Y
elif Z>X and Z>Y:
large=Z
Sum=X+Y+Z
middle=Sum-(small)-(large)
print("The ascending order is : ",small,middle,large)

1
IN SCRIPT MODE:

IN SHELL MODE:

2
FLOW CHART:

START

Input 3
numbers

user

Store 3 empty variable

False X<Y
and Small = X

X<Z

TRUE Small
Small==YY
False Y<X
and
Y<Z

False TRUE
Z<Y Small = Z
and
Z<X

Print (‘don’t
3
repeat the
number’)
False TRUE
X>Y
and Large = X
X>Z

False Y>X TRUE


and Large = Y

Y>Z

False Z>y
TRUE
and Large =
Z>X Z

Sum=X+Y+Z

middle=Sum-
(small)-(large)

print("The ascending order


is : ",small,middle,large)

STOP

4
Flow CHART: (PART NO 2):

START

X=int(input(‘one side’)

Y=int(input(‘other side’)

Z=int(input(‘third side’)

True False
X==Y==Z

Print
(‘equivillant X===Y and Y==Z
or
triangle’)
Z==X and X==Z

STOP
5
Python program to check a triangle is equilateral, isosceles or
scalene:

PROGRAM:
x = int (input ("\"Enter one side of triangle = \""))
y = int (input ("\"Enter second side of triangle = \""))
z = int (input ("\"Enter third side of triangle = \""))
if x == y == z:
print ('Triangle is "Equilateral triangle"')
elif x==y or y==z or z==x:
print ('Triangle is "Isosceles triangle"')
else:
print ('This triangle is "Scalene triangle""')

IN SCRIPT MODE:

IN SHELL MODE:

6
QUESTION NO 2
Assume d1 and d2 have the numbers on 2 dice. Accept d1 and d2 as
input. First, check to see that they are in the proper range for dice. If not,
print a message. Otherwise, determine the outcome. If the sum is 7 or
11, print winner. If the sum is 2, 3 or 12, print loser. Otherwise print the
points.

ANSWER:
PROGRAM:

d1 = int (input ("Enter number for dice_1: "))


d2 = int (input ("Enter number for dice_2: "))
if (d1 >= 1) and (d1 <= 6) and (d2 >= 1) and (d2 <= 6):

7
sum = d1 + d2
if sum == 7 or sum == 11:
print("Winner")
elif sum == 2 or sum == 3 or sum == 12:
print("Loser")
else:
print ("Points: ", str(sum))
else:
print ("Number not in range")

IN SCRIPT MODE:

8
IN SHELL MODE:

You might also like