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

Art of Thinking

Algorithmic Thinking | Flowchart

Assignment 1

1. Which box type is used for what in a Flowchart?


• Match the columns
• One shape can be used for two things

2. What do the following flowcharts do? Write the Equivalent Python Code for the Same.
Treat each flowchart as a Function with its INPUT and OUTPUT. Name the function
appropriately once you figure out what it does. [Note: modulo(x, y) in python is x % y]

(a) (b)

(c) (d)
3. Draw the flow chart and implement the Python code for the following:

a) You are given a Sphere with radius sr and a Cone with radius cr and height ch. Write
a python function (def sphere_or_cone) and its flowchart to return true if Sphere
has a larger volume and false if Cone has a larger volume. What are the two input
types of this function (NOTE: Club the parameters of each shape together in a tuple)

b) You are given two cuboids P and Q. Cuboid P has dimensions (pl, pb, ph) and Cuboid
Q has dimensions (ql, qb, qh). Write a function and flowchart to return the volume of
that cuboid whose surface area is larger. What are the two input types of this
function (NOTE: You can club the parameters of each cuboid as a tuple)

4. Convert the following Python function into a flowchart:

def sort_descending(a, b, c):


if (a > b):
if (b > c):
ans = (a, b, c)
else: # c >= b
if (a > c):
ans = (a, c, b)
else: # c > a
ans = (c, a, b)
else: # b >= a
if (b > c):
if (a > c):
ans = (b, a, c)
else: # a <= c
ans = (b, c, a)
else: # c >= b
ans = (c, b, a)

Trace the Path to check the output for the following:


• sort_descending(1, 2, 3)
• sort_descending(1, 3, 2)
• sort_descending(2, 1, 3)
• sort_descending(2, 3, 1)
• sort_descending(3, 1, 2)
• sort_descending(3, 2, 1)

Check that in all cases the final output is always (3, 2, 1).

You might also like