0% found this document useful (0 votes)
34 views6 pages

SP21-Introduction To ICT: Assignment 3 (Solution)

The document provides sample solutions for two Python programming assignments. The first assignment involves sorting numbers and checking triangle types. The second involves simulating dice rolls for a game and determining a winner, loser or points based on the roll total. Flowcharts and code are provided for each problem.

Uploaded by

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

SP21-Introduction To ICT: Assignment 3 (Solution)

The document provides sample solutions for two Python programming assignments. The first assignment involves sorting numbers and checking triangle types. The second involves simulating dice rolls for a game and determining a winner, loser or points based on the roll total. Flowcharts and code are provided for each problem.

Uploaded by

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

SP21- Introduction to ICT

Assignment 3 (Solution)

****Please note that this is sample solution to these questions. There can be multiple solutions as well.
As there are multiple ways you can solve these.

Question 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.

Code:
one = int(input("Please input first number : "))
two = int(input("Please input second number : "))
three = int(input("Please input third number : "))

if one < two and three < two:


if one > three:
print(three, one, two)
else:
print(one, three, two)
elif one < three and two < three:
if one > two:
print(two, one, three)
else:
print(one, two, three)
elif two < one and three < one:
if three > two:
print(two, three, one)
else:
print(three, two, one)
else:
print(one, two, three)
Flow Chart:
b)
Code:
print("Input lengths of the triangle sides: ")
x = int(input("x: "))
y = int(input("y: "))
z = int(input("z: "))

if x == y == z:
print("Equilateral triangle")
elif x==y or y==z or z==x:
print("isosceles triangle")
else:
print("Scalene triangle")
Flow Chart:
Question 2
Write python code for the following.
a) 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.
Code:
d1 = int(input("Choose number on dice 1"))
d2 = int(input("Choose number on dice 2"))
sum = d1+d2
if(d1>6 and d2>6):
print("Number does not lie in dice raange")
elif(sum==7 or sum==11):
print("winner")
elif(sum==2 or sum==3 or sum==12):
print("Loser")
else:
print("Points are: ",sum)

You might also like