Pseudocode: Difference between revisions
Mr. MacKenty (talk | contribs) No edit summary |
Mr. MacKenty (talk | contribs) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 17: | Line 17: | ||
<br> | <br> | ||
* [[:media:Pseudo Code Practice Problems.pdf|Click here for an excellent pseudocode practice guide]] | * [[:media:Pseudo Code Practice Problems.pdf|Click here for an excellent pseudocode practice guide]] | ||
== Please remember == | |||
# Always open an IF and close an IF as clearly as possible | |||
# Always open a LOOP and close a LOOP as clearly as possible | |||
# Always make your variable names meaningful and obvious. X isn't good but student_first_name is excellent. | |||
# Always make sure you have comments to explain you logic and process. | |||
# Ensure your pseudocode is legible | |||
# Ensure your pseudocode is at the right level of depth | |||
== Common psuedocode verbs == | == Common psuedocode verbs == | ||
Line 41: | Line 49: | ||
else | else | ||
Print "failed" | Print "failed" | ||
End if | |||
</code> | </code> | ||
<br /> | <br /> | ||
Line 53: | Line 62: | ||
<br /> | <br /> | ||
<code> | <code> | ||
Set total to zero | # Set total to zero | ||
# Set grade counter to one | |||
Set grade counter to one | # While grade counter is less than or equal to ten | ||
# Input the next grade | |||
While grade counter is less than or equal to ten | # Add the grade into the total | ||
# end while | |||
Input the next grade | # Set the class average to the total divided by ten | ||
Add the grade into the total | |||
Set the class average to the total divided by ten | |||
Print the class average. | Print the class average. |
Latest revision as of 16:03, 3 April 2024
Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a normal programming language, but is intended for human reading rather than machine reading.[1]
Pseudocode is a simple way of writing programming code in English. Pseudocode is not actual programming language. It uses short phrases to write code for programs before you actually create it in a specific language. Once you know what the program is about and how it will function, then you can use pseudocode to create statements to achieve the required results for your program.[2]
Official IB pseudocode guide[edit]
There are two different versions of the IB Pseudocode guide:
- Click here to view a file describing approved notation, including pseudocode This is the approved notation sheet from the IB.
- Click here for a more in-depth pseudocode guide
Some practice links[edit]
This is a SUPERB guide I have used with high gratitude from Queen Anne's County Public Schools
Please remember[edit]
- Always open an IF and close an IF as clearly as possible
- Always open a LOOP and close a LOOP as clearly as possible
- Always make your variable names meaningful and obvious. X isn't good but student_first_name is excellent.
- Always make sure you have comments to explain you logic and process.
- Ensure your pseudocode is legible
- Ensure your pseudocode is at the right level of depth
Common psuedocode verbs[edit]
Common Action Keywords[3]
Several keywords are often used to indicate common input, output, and processing operations.
- Input: READ, OBTAIN, GET
- Output: PRINT, DISPLAY, SHOW
- Compute: COMPUTE, CALCULATE, DETERMINE
- Initialize: SET, INIT
- Add one: INCREMENT, BUMP
Examples of pseudocode[edit]
[4] Example 1:
If student's grade is greater than or equal to 60
Print "passed"
else
Print "failed"
End if
Question for you to think about:
[5] Example 2:
- Set total to zero
- Set grade counter to one
- While grade counter is less than or equal to ten
- Input the next grade
- Add the grade into the total
- end while
- Set the class average to the total divided by ten
Print the class average.
Do you understand this?[edit]
Review the python code below and then re-type it in pseudocode.
Please paste and run this code into your Python IDE :
import random
secret_number = random.randint(0,100)
guess = 0
game = 1
while True:
print("This is guess: " + str(guess))
print("This is game: " + str(game))
players_guess = int(input("I'm thinking of a number between 1 and 100. What is your guess: "))
if players_guess == secret_number:
print("You won!")
play_again = input("Do you want to play again (Y or N)? ")
if play_again == "Y" or play_again == "y" or play_again == "yes":
guess == 0
game = game + 1
secret_number = random.randint(0,100)
else:
break
elif players_guess < secret_number:
print("This guess is to low.")
guess = guess + 1
elif players_guess > secret_number:
print("This guess is to high")
guess = guess + 1
Click the expand link to see one possible solution, but NOT before you have tried and failed! The solution below was graciously provided by Emiko, an 8th grade student in 2016.
Pick a random number.
Set the secret number to a number that is between 0 and 100.
Set the number of guesses to start with.
Set the number of games to 1.
While true, print ("This is guess: " +(number of guesses) and print ("This is game: + (number of games).
Obtain the player's guess by asking for an input of their guess.
If the player guessed the secret number, print ("You won!") and ask "do you want to play again?"
If play again is "y", set guess back to zero and add one to the number of games played. Also, choose another different random secret
number between 0 and 100. Else, if play again is no, end or break the code.
If the player's guess is is lower than the secret number, print ("The guess is too low.") and add one to the number of guesses.
Else, if the number is higher than the secret number, print ("This guess is too high.") and add one to the number of guesses.
Why is this so important?[edit]
When you are first building a program, we don't really care about the actual LANGUAGE or SYNTAX you will use. Rather, we care about your logic. Pseudocode helps you by forcing you to think logically rather than about syntax.