How to Convert Python Code to Effective Pseudocode?

  • Python
  • Thread starter Mr Davis 97
  • Start date
  • Tags
    Code Python
In summary, the conversation is about converting python code to pseudocode and the considerations for making it general and understandable to non-technical individuals. The main points discussed are identifying and describing each line of code in human terms, including necessary inputs and symbols, and balancing between generality and details.
  • #1
Mr Davis 97
1,462
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
  • #2
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.
 
  • #3
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:eek:zs"?
 
  • #4
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.
 
  • #5
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?
 
  • #6
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.
 
  • #7
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
 
  • #8
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:
 

1. What is pseudocode?

Pseudocode is a simple, high-level description of a computer program or algorithm, written in plain English or a simplified programming language. It is used to plan out the logic and steps of a program before writing actual code.

2. Why is converting code to pseudocode important?

Converting code to pseudocode can help clarify the logic and structure of a program, making it easier to understand and troubleshoot. It can also serve as a helpful guide when writing the actual code, saving time and reducing errors.

3. How do I convert code to pseudocode?

To convert code to pseudocode, start by breaking down the code into smaller, more manageable steps. Then, use plain language to describe each step in a logical order, using variables and conditional statements as needed. It's important to keep the pseudocode simple and easy to understand.

4. Can pseudocode be used for any programming language?

Yes, pseudocode can be used for any programming language. However, it is typically written in a language that is similar to the one being used for the actual code. This makes it easier to translate the pseudocode into actual code later on.

5. Is pseudocode the same as a flowchart?

No, pseudocode and flowcharts are two different types of planning tools for programming. While pseudocode uses written descriptions, flowcharts use visual symbols and diagrams to represent the steps and logic of a program. Both can be useful in different situations, and some programmers may use both in their planning process.

Similar threads

  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
7
Views
946
  • Programming and Computer Science
Replies
2
Views
771
  • Programming and Computer Science
2
Replies
55
Views
4K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
3
Views
320
  • Programming and Computer Science
Replies
1
Views
283
Replies
6
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
Back
Top