Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help on converting code to pseudocode?

  1. Oct 1, 2015 #1
    I have the following python code:

    YYCRTe6.png

    I need to know how to best convert this to pseudocode. On one hand, I am afraid of making it too python specific, and on the other hand, it can't be too general. For example, for the 2nd and 3rd blocks of code, how would I write them in pseudocode? What should I include and what should I leave out?
     
  2. jcsd
  3. Oct 1, 2015 #2

    DaveC426913

    User Avatar
    Gold Member

    Try describing what each line is doing to a non-techie.

    You don't leave things out, you simply describe them in more human terms.

    find position of colon1
    take everything to the left of colon1, multiply it by 16
    take everything to right of colon1 and add the above to it

    This may or may not be the type of pseudocode acceptable in your class , for example, whether you should assign those values to variable to be more explicit.
     
  4. Oct 1, 2015 #3
    Okay, I think that helps clear things up. So for the first two inputs would I just say "get initialWeight" our do I have to describe that the input is of the form "lbs:eek:zs"?
     
  5. Oct 1, 2015 #4

    DaveC426913

    User Avatar
    Gold Member

    Well, that's up to you. It's a balance between making the code generalized and keeping the details.
    Yea, I would include it. The code needs it, regardless of what language it gets written in.
     
  6. Oct 1, 2015 #5
    Alright, thanks! One final question. I know that the universal symbol for modulo division is mod. But what should I use or say to indicate integer division?
     
  7. Oct 1, 2015 #6

    DaveC426913

    User Avatar
    Gold Member

    The / is pretty universal for division. You'd also specify that the result should be integerized.
     
  8. Oct 4, 2015 #7

    Mark44

    Staff: Mentor

    Python uses two different symbols for division, unlike C.
    Regular division (floating point result) /
    Integer division (floor) //

    For example, 6/5 == 1.2, while 6//5 == 1
     
  9. Oct 5, 2015 #8

    DaveC426913

    User Avatar
    Gold Member

    Which is a good reason why he should not use it is his pseudocode. :wink:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Help on converting code to pseudocode?
  1. Help Convert Code (Replies: 0)

Loading...