Question

In: Computer Science

Intro to Python 1. Draw a structure chart for one of the solutions to the programming...

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?

Solutions

Expert Solution

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)


Related Solutions

"""    CS 125 - Intro to Computer Science    File Name: CS125_Lab1.py    Python Programming...
"""    CS 125 - Intro to Computer Science    File Name: CS125_Lab1.py    Python Programming    Lab 1    Name 1: FirstName1 LastName1    Name 2: FirstName2 LastName2    Description: This file contains the Python source code for deal or no deal. """ class CS125_Lab1(): def __init__(self): # Welcome user to game print("Let's play DEAL OR NO DEAL")    # Define instance variables and init board self.cashPrizes = [.01, .50, 1, 5, 10, 50, 100, 250, 500, 1000, 5000,...
Explain H&M Organizational Structure. and draw the Chart!
Explain H&M Organizational Structure. and draw the Chart!
python 2.7 Dash How to draw a bar & line & pie chart for below dict...
python 2.7 Dash How to draw a bar & line & pie chart for below dict data by using Dash? The value is the percentage of each month. So total will be 100. {'Mar': 17.973851593144104, 'Feb': 10.540182187664472, 'Sep': 8.200076731097335, 'Apr': 12.080717324339435, 'Jan': 16.118724221364918, 'Nov': 12.29654875876966, 'Dec': 11.378407574427893, 'Oct': 11.411491609192186} Please provide the python 2.7 code.
Programming Activity 1(Python) Utilise a count-based iteration structure that will accepts the data listed below and...
Programming Activity 1(Python) Utilise a count-based iteration structure that will accepts the data listed below and produce the total purchase amount. Your final report should be similar to the one show below. Input Data: Item Description Item Price Salomon Fish $ 26.97 Ribeye Steak $ 12.98 Sweet Corn $ 4.96 Asparagus $5.92 Output: Item Description Item Price ================================= Salomon Fish $26.97 Ribeye Steak $ 12.98 Sweet Corn $ 4.96 Asparagus $ 5.92 Your total purchase: $ xx.xx
Solve using PYTHON PROGRAMMING Write a script that reads a file “cars.csv”, into a pandas structure...
Solve using PYTHON PROGRAMMING Write a script that reads a file “cars.csv”, into a pandas structure and then print a. the first 3 rows and the last 3 of the dataset b. the 3 cars with the lowest average-mileage c. the 3 cars with the highest average-mileage. Solve using PYTHON PROGRAMMING
2- Draw the BCG Chart and give an example of it 3-Draw Product Life Cycle Chart...
2- Draw the BCG Chart and give an example of it 3-Draw Product Life Cycle Chart and give an example of it 4-list the Break Even Model and draw the chart and give an example of it
Python Programming Revise the ChatBot program below. There needs to be one list and one dictionary...
Python Programming Revise the ChatBot program below. There needs to be one list and one dictionary for the ChatBot to use. Include a read/write function to the program so that the program can learn at least one thing and store the information in a text document. ChatBot program for revising: # Meet the chatbot Eve print('Hi there! Welcome to the ChatBot station. I am going to ask you a series of questions and all you have to do is answer!')...
The problem is below. This is for an intro to Python class, so, if possible keep...
The problem is below. This is for an intro to Python class, so, if possible keep it relatively simple and 'basic.' The code in bold below is given: def trade_action(current_stock, purchase_price, current_price, investment): # Write your code here. return "Hold Shares." Instructions: Many investment management companies are switching from manual stock trading done by humans to automatic stock trading by computers. You've been tasked to write a simple automatic stock trader function that determines whether to buy, sell, or do...
Python Programming 1. Write a function name split_name which takes one parameter called name. If the...
Python Programming 1. Write a function name split_name which takes one parameter called name. If the name parameter value is a name in the form LastName, FirstName(e.g., ”Grounds, Nic”) then the function should return a list of two elements where FirstName is the first element and LastName is the second element. If the name parameter value is a name in the form FirstName LastName(e.g., ”Nic Grounds”) then the function should return a list of two elements where FirstName is the...
* Python * * Python Programming * Part 1: Product Class Write a class named Product...
* Python * * Python Programming * Part 1: Product Class Write a class named Product that holds data about an item in a retail store.   The class should store the following data in attributes: product id, item description, units in inventory, and price. Write the __init__ method to require all four attributes. Also write a __str__ method for debugging output.    Once you have written the class, write a main() function that creates three Product objects and stores the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT