Turn on thread page Beta

Please help me finish my flowchart for Problem Solving module of Foundation Computing watch

Announcements
    • Thread Starter
    Offline

    14
    ReputationRep:
    One of the questions on the first assignment for my Problem Solving module concerns printing a list of all prime numbers between 10 and 261.

    First I had to write a pseudo-code which could be given to a programmer and re-written in any programming language. I did that part fine.

    The second part of the question is to draw a flowchart representing the algorithm required to print the list of prime numbers. Couldn't quite get my head around it, so I decided to write a small program in Python to print the list of primes and then try to figure the flowchart out from that.

    So I wrote the program (and I don't even need the code for the assignment, only pseudo-code) and have partially drawn my flowchart, but I'm getting confused about how to complete the flowchart.

    I feel like I'm close, I just need to show how the flow of execution exits the second (the nested one) 'for' loop and how it continues onto the 'if prime is True' part, where it adds the current value of 'i' to the empty list.

    I can't understand how to show that in the flowchart, unless I add another testing condition of some kind, but I can't figure out what that would be. Something like "if count==i", except clearly in the program, that will never be true. Or "if count !<i", which again will never be true.

    Please help?!
    Offline

    18
    ReputationRep:
    Have a look at this brief example of a for-loop in a flow diagram:
    https://stackoverflow.com/a/879273

    Note that the arrows are all connected so that as you trace through the flowchart step-by-step you will be repeating the same sequence of steps many times; your diagram above only hits each step one at a time.


    A few other suggestions
    - Don't be so wordy in each step.
    - Don't use the word "if" -- a condition is implicit by the symbol you are using. The condition should merely show the conditional logic
    - Separate your steps into individual instructions -- don't use words like "iterate", "count", "range", etc -- these aren't single instructions. Repetition in a flow diagram is illustrated by arrows which branch back to an earlier step.


    For nested loops, have a look at this example:
    https://stackoverflow.com/a/43697736
    Look carefully how the nested loop is visualised as an "inner" loop within an "outer" loop -- because that is how the structure of your code is too - i.e. you have a loop within a loop.

    Lastly, I'd recommend trying to distance yourself a little from the convenient high-level notation that Python gives you and remember that a single line in Python might be doing many things which cannot be represented in one step in a flow diagram.

    For example 'for i in range(10, 262)' is a single line which actually does 3 different things at different stages:
    1) Before the first conditional check, it initialises "i" to 10.
    2) Conditional check of "i" for equality against 262
    3) Before subsequent conditional checks, it increments "i"

    This being the case, those 3 steps must also be 3 separate steps in your flow diagram too (happening in the appropriate places, of course).
    • Thread Starter
    Offline

    14
    ReputationRep:
    (Original post by winterscoming)
    Have a look at this brief example of a for-loop in a flow diagram:
    https://stackoverflow.com/a/879273

    Note that the arrows are all connected so that as you trace through the flowchart step-by-step you will be repeating the same sequence of steps many times; your diagram above only hits each step one at a time.


    A few other suggestions
    - Don't be so wordy in each step.
    - Don't use the word "if" -- a condition is implicit by the symbol you are using. The condition should merely show the conditional logic
    - Separate your steps into individual instructions -- don't use words like "iterate", "count", "range", etc -- these aren't single instructions. Repetition in a flow diagram is illustrated by arrows which branch back to an earlier step.


    For nested loops, have a look at this example:
    https://stackoverflow.com/a/43697736
    Look carefully how the nested loop is visualised as an "inner" loop within an "outer" loop -- because that is how the structure of your code is too - i.e. you have a loop within a loop.

    Lastly, I'd recommend trying to distance yourself a little from the convenient high-level notation that Python gives you and remember that a single line in Python might be doing many things which cannot be represented in one step in a flow diagram.

    For example 'for i in range(10, 262)' is a single line which actually does 3 different things at different stages:
    1) Before the first conditional check, it initialises "i" to 10.
    2) Conditional check of "i" for equality to 262
    3) Before subsequent checks, it increments "i"

    This being the case, those 3 steps must also be 3 separate steps in your flow diagram too (happening in the appropriate places, of course).
    Yeah, thanks. I would have just put the Python code inside the relevant shapes on the flowchart, but I'm pretty sure the lecturer wants it in pseudo code so that it could be given to somebody who might now know Python and they could write a program from it.

    Also, sh*t. I thought I'd finished this now but your comment about multiple functions in one line has now made me realise I need to re-draw the whole thing with a bunch of extra steps. It's already unnecessarily overcomplicated, considering the Python code and the pseudo-code are both only about 10 lines.
    • Thread Starter
    Offline

    14
    ReputationRep:
    (Original post by winterscoming)
    Have a look at this brief example of a for-loop in a flow diagram:
    https://stackoverflow.com/a/879273

    Note that the arrows are all connected so that as you trace through the flowchart step-by-step you will be repeating the same sequence of steps many times; your diagram above only hits each step one at a time.


    A few other suggestions
    - Don't be so wordy in each step.
    - Don't use the word "if" -- a condition is implicit by the symbol you are using. The condition should merely show the conditional logic
    - Separate your steps into individual instructions -- don't use words like "iterate", "count", "range", etc -- these aren't single instructions. Repetition in a flow diagram is illustrated by arrows which branch back to an earlier step.


    For nested loops, have a look at this example:
    https://stackoverflow.com/a/43697736
    Look carefully how the nested loop is visualised as an "inner" loop within an "outer" loop -- because that is how the structure of your code is too - i.e. you have a loop within a loop.

    Lastly, I'd recommend trying to distance yourself a little from the convenient high-level notation that Python gives you and remember that a single line in Python might be doing many things which cannot be represented in one step in a flow diagram.

    For example 'for i in range(10, 262)' is a single line which actually does 3 different things at different stages:
    1) Before the first conditional check, it initialises "i" to 10.
    2) Conditional check of "i" for equality against 262
    3) Before subsequent conditional checks, it increments "i"

    This being the case, those 3 steps must also be 3 separate steps in your flow diagram too (happening in the appropriate places, of course).
    Thank you. I was a bit stressed about it yesterday but you've certainly helped me to understand what needs to be done now. Your response is much appreciated.
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: December 15, 2018

University open days

  • University of East Anglia
    All Departments Open 13:00-17:00. Find out more about our diverse range of subject areas and career progression in the Arts & Humanities, Social Sciences, Medicine & Health Sciences, and the Sciences. Postgraduate
    Wed, 30 Jan '19
  • Aston University
    Postgraduate Open Day Postgraduate
    Wed, 30 Jan '19
  • Solent University
    Careers in maritime Undergraduate
    Sat, 2 Feb '19
Poll
Brexit: Given the chance now, would you vote leave or remain?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.