In: Computer Science
Intro to Python
1. Draw a structure chart for one of the solutions to the programming projects of Chapters 4 and 5. The program should include at least two function definitions other than the main function.
2.Describe the processes of top-down design and stepwise refinement. Where does the design start, and how does it proceed?
Answer: Hello!! Dear student Kindly finds your solution here. If you have any queries, feel free to ask me. Thanks.
Python program with two functions-
def is_even_num(l):
enum = []
for n in l:
if n % 2 == 0:
enum.append(n)
return enum
def test_prime(n):
if (n==1):
return False
elif (n==2):
return True;
else:
for x in range(2,n):
if(n % x==0):
return False
return True
print(test_prime(5))
print(is_even_num([1, 2, 3, 4, 5, 6, 7,10 ]))
Top-Down Design- A top-down approach is also called a stepwise design. This type of design is essentially the breaking down of a program to gain insight into the sub-functions that make it up. In this design, an overview of the program is formulated, specifying but not detailing any first-level subsystems. Each sub-functions is then refined in yet greater detail, sometimes in many additional subfunction levels, until the entire specification is reduced to base elements. Once they are built we can put them together, making the entire program form these individual components.
The top design begins by specifying complex pieces and then dividing them into successively smaller pieces.
Example-
Suppose we want to implement a program that will ask the users to enter a list of numbers and then will answer which pairs of numbers are evenly divisible. For example- we have a list of integers- 1,2,3,4,5,6,8 is entered. The program should give result-
1 is evenly divisible by 1
2 is evenly divisible by 1 2
3 is evenly divisible by 1 3
4 is evenly divisible by 1 2 4
5 is evenly divisible by 1 5
6 is evenly divisible by 1 2 3 6
8 is evenly divisible by 1 2 4 8
To perform this task, a top-down design would start with getting the input from the user.
Step -1 list = input(“Please enter a list of integers”)
Step-2 list1 = []
Step-3 for x in list.split[]:
Step-4 list1.append(int(x))
Step-5
Step-6 evenlyDivisible(list)