Python How to Convert Python Code to Effective Pseudocode?

  • Thread starter Thread starter Mr Davis 97
  • Start date Start date
  • Tags Tags
    Code Python
Click For Summary
The discussion focuses on converting Python code into pseudocode while balancing specificity and generality. Key points include the need to describe code operations in layman's terms, such as finding the position of a colon, multiplying values, and adding results. Participants emphasize the importance of including necessary details, like the input format "lbs:ozs," to ensure clarity in the pseudocode. There is also a discussion about representing integer division, with suggestions to use the division symbol (/) and specify that the result should be an integer. The conversation highlights the differences in division symbols between Python and other programming languages, noting that Python uses distinct symbols for regular and integer division, which should be avoided in pseudocode for broader applicability.
Mr Davis 97
Messages
1,461
Reaction score
44
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?
 
Technology news on Phys.org
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.
 
DaveC426913 said:
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.

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:ozs"?
 
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.
 
DaveC426913 said:
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.
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?
 
Mr Davis 97 said:
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?
The / is pretty universal for division. You'd also specify that the result should be integerized.
 
Mr Davis 97 said:
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?
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
 
Mark44 said:
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
Which is a good reason why he should not use it is his pseudocode. :wink:
 

Similar threads

  • · Replies 40 ·
2
Replies
40
Views
973
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
55
Views
6K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K