• 0

how do i write this in pseudocode?


Question

i understand this is not vb or c++ or anything, i used a program called python and its pretty simple to understand if someone could help me write it in pseudocode that would be awesome thankyou.

#version 0.0.5

class Game:

# Initialises variables

def __init__(self):

self._exit = False

# Array of known commands

self._commands = {

'go': self._go,

'quit': self._quit,

"look" : self._look}

# Array of go sub commands, used by _go

self._commands_go = {"north": self._go_north,

"south" : self._go_south,

"east" : self._go_east,

"west" : self._go_west,

"up" : self._go_up,

"down" : self._go_down}

# Method for parsing command, if it gets "comamnd" returns ("command",None)

@staticmethod

def parse_command(string):

index = string.find(' ')

if index < 0:

return (string, None)

return (string[:index], string[index+1:])

# This is main method; the only one which should be called from outside

# It will just read data from input in never ending loop and parse commands

def run(self):

while not self._exit:

src = input('> ')

(command,args) = Game.parse_command( src)

# Do we have this command, execute it

if command in self._commands:

self._commands[command](args)

else:

print("huh?")

#######################################################

############## All game commands go here ##############

#######################################################

def _quit(self,args):

self._exit = True

print("OK ... but a small part of you may never leave until you have personally saved Muirfieland from the clutches of evil .. Bwahahahahahah (sinister laugh)")

def _look(self,args):

print("You see nothing but endless void stretching off in all directions")

# movement handling, will get executed when user types 'go ...' and '...' will be in arg

def _go(self,args):

if args is None:

print("please tell me more",)

return False

# splits sub command and arguments

(command,args) = Game.parse_command(args)

if command not in self._commands_go:

print( "Sorry, I'm afraid I can't do that !")

return False

self._commands_go[command](args)

return True

# directions

def _go_north(self, args):

print("You wander of in the direction of north")

def _go_south(self, args):

print("You wander of in the direction of south")

def _go_east(self, args):

print("You wander of in the direction of east")

def _go_west(self, args):

print("You wander of in the direction of west")

def _go_up(self, args):

print("You wander of in the direction of up")

def _go_down(self, args):

print("You wander of in the direction of down")

#runs the game

game = Game()

game.run()

Link to comment
https://www.neowin.net/forum/topic/1149082-how-do-i-write-this-in-pseudocode/
Share on other sites

15 answers to this question

Recommended Posts

  • 0

If you understand the code that you have pasted then there should be no need for us to write the pseudocode for you. As a general rule in development, the pseudocode comes before the real code in an attempt to keep you focused. If you understand the code above then you can just break down what it does in to simple English.

  • Like 2
  • 0

strange question, I agree with Intrinsica. To write it in pseudocode you just have to describe what it does in normal english without elaborating too much. It's not like there is an accepted standard for pseudocode, because that would make it code ;)

  • 0
  On 26/04/2013 at 07:26, Intrinsica said:

If you understand the code that you have pasted then there should be no need for us to write the pseudocode for you. As a general rule in development, the pseudocode comes before the real code in an attempt to keep you focused. If you understand the code above then you can just break down what it does in to simple English.

no its not my homework...

i agree with what your saying but ive already written out the code..

just a few questions, do define something in pseudocode do you "dim" it in pseudocode?

heres what ive got so far.


class game
dim _init_(self):
self._exit = false
self._command = { "go" : self._go, "quit" : self._quit, "look" : self._look}
self._commands_go = {"north" : self._go_north, "south" : self._go_south, "east" : self._go_east, "west" : self._go_west, "up" : self._go_up, "down" : self._go_down}
@staticmethod
dim parser(string):
index = string. find (" ")
if index < 0 then
return (string, none)
end if
return (string(:index), string(index+1:))
dim run(self):
while not self._exit:
src = input("> "
(command,args) = game.parse_command(src)

if command in self._commands then
self._commands[command](args)
else:
print("huh?")
end if
dim_quit(self,args):
self._exit = true
print("OK ... but a small part of you may never leave until you have personally saved Muirfieland from the clutches of evil .. Bwahahahahahah (sinister laugh)")
dim _look(self,args):
print("You see nothing but endless void stretching off in all directions")
dim_go(self,args):
if args is none then
print("please tell me more")
return false
end if
(command,args) = game.parse_command(args)
if command not in self._commands_go then
print("Sorry, I'm afraid I can't do that !")
return false
end if
self._commands_go[command](args)
return true
dim _go_north(self, args):
print("You wander of in the direction of north")
dim _go_south(self, args):
print("You wander of in the direction of south")
dim_go_east(self, args):
print("You wander of in the direction of east")
dim_go_west(self, args):
print("You wander of in the direction of west")
dim_go_up(self, args):
print("You wander of in the direction of up")
dim_go_down(self, args):
print("You wander of in the direction of down")
game = game()
game.run()

[/CODE]

  • 0

Ok, a fair start. But here's the thing: I try to think of pseudocode like when I'm trying to explain to an end user what I'm doing and they don't understand computers. It's sort of in between actual code and pure English.

For example:

Request value for int from user
if int &gt; 5
goto [step 2]
else
goto [step 3]

[step 2] = say "Hello"

[step 3] = say "Leave me alone"

From that you can understand what is happening in the code without having to be a programmer. Note that the above example isn't the best in the world, but hopefully it helps to get the idea across.

  • 0
  On 26/04/2013 at 09:16, Intrinsica said:

Ok, a fair start. But here's the thing: I try to think of pseudocode like when I'm trying to explain to an end user what I'm doing and they don't understand computers. It's sort of in between actual code and pure English.

For example:

Request value for int from user
if int &gt; 5
goto [step 2]
else
goto [step 3]

[step 2] = say "Hello"

[step 3] = say "Leave me alone"

From that you can understand what is happening in the code without having to be a programmer. Note that the above example isn't the best in the world, but hopefully it helps to get the idea across.

i understand what you're saying, but I'm defining and using classes, not if statements

  • 0
  On 26/04/2013 at 10:22, jacobace said:
i understand what you're saying, but I'm defining and using classes, not if statements

You're right, but I'm also not going to write out your pseudocode for you. ;)

At the top of your code you set your commands and sub-commands.

Next it looks like you're waiting for the user to input a command.

Once the input has been given, the program jumps to the necessary location to execute the result.

The above is more English than it is pseudocode, and you would also want to provide more detail about each of the commands on the last section.

There's no need to think in classes and arrays for pseudocode (at least, in my mind). The whole point of pseudocode is that it is a way for anyone to understand what the program is doing at each step, almost like the commenting that you already added in the code itself.

  • 0

Pseudocode is usually used so non-programmers can understand what a piece of code does, or to express to a programmer what his/her code should do, without actually knowing any programming language.

Your 'pseudocode' looks like you just replaced 'def' with 'dim', and 'if... :' with 'if...then'.

Ask yourself this; would a non-programmer even know what 'dim' is?

You say your code is a class and some functions. I say it could very easily be expressed in a series of if statements.


Get user input
If input 1st word = "go" then
If input 2nd word = "north" then
print "wandering north"
else if input 2nd word = "south" then
print "wandering south"
...
end 2nd word check
else if input 1st word = "look"
print "you see nothing"
...
end 1st word check
[/CODE]

I'm sure if you give that to your mom, she'd probably grasp what the code is trying to do.

  • 0
  On 26/04/2013 at 11:50, GreenMartian said:

Pseudocode is usually used so non-programmers can understand what a piece of code does, or to express to a programmer what his/her code should do, without actually knowing any programming language.

Your 'pseudocode' looks like you just replaced 'def' with 'dim', and 'if... :' with 'if...then'.

Ask yourself this; would a non-programmer even know what 'dim' is?

You say your code is a class and some functions. I say it could very easily be expressed in a series of if statements.


Get user input
If input 1st word = "go" then
If input 2nd word = "north" then
print "wandering north"
else if input 2nd word = "south" then
print "wandering south"
...
end 2nd word check
else if input 1st word = "look"
print "you see nothing"
...
end 1st word check
[/CODE]

I'm sure if you give that to your mom, she'd probably grasp what the code is trying to do.

oh ok, i always through pseudocode was mean for "non programmers" to understand YOUR code, not how it works

  On 26/04/2013 at 11:08, saltysaltybk said:

This is homework- my school sniffer is in full force.

im just doing purely a out of my own curiosity, yes im in year 12 software design and development, and i need to know pseudocode but my skills arent exactly very good, so i got an existing program which was a project and im using that as an example.

  • 0
  On 26/04/2013 at 12:09, jacobace said:

oh ok, i always through pseudocode was mean for "non programmers" to understand YOUR code, not how it works

Well, pseudocode doesn't really have a rigid definition. You can do whatever you like, depending on the target audience.

If you're trying to explain a program you just wrote to your mom, then you probably want to express it in REALLY simple terms as I did above.

If you're trying to explain the code to a fellow programmer unfamiliar to Python, you could probably use some jargons from a language that he understands, and simplify the code (e.g. don't even bother including the 'self' argument. It doesn't contribute to what the code does).

It's a bit like public speaking; know your audience, and how much to 'dumb it down' so they understand what you're talking about.

  • 0
  On 26/04/2013 at 12:22, GreenMartian said:
Well, pseudocode doesn't really have a rigid definition. You can do whatever you like, depending on the target audience.
I wish they had told us that in university back when they started asking for programs in "pseudocode"... Everyone was so confused as to what to write exactly!
  • 0
  On 26/04/2013 at 13:21, Asik said:

I wish they had told us that in university back when they started asking for programs in "pseudocode"... Everyone was so confused as to what to write exactly!

thats exactly how i feel!!,like we went over pseudocode in class, but everyone has there weaknesses and unfortunatly pseudocode is mine, and i suppose the "form" of pseudocode we learned was different because i cant find that 'form' on the internet or anything. which is why im asking people for help.

  On 26/04/2013 at 13:21, Asik said:

I wish they had told us that in university back when they started asking for programs in "pseudocode"... Everyone was so confused as to what to write exactly!

i mostly dont learn software from websites and help, i learn from examples and i see how they do it and pick up techniques/theory from that

  • 0

It's just whatever you want it to be really. I feel most comfortable coding in Java, so my psuedocode basically looks like Java but leaves out a lot of the more complicated stuff (less strict with type safety, leaving out ; in places, ...).

Psuedocode should just be readable, and you should be able to create real code from psuedocode so it shouldn't be too concise. Just enough to make people understand what it does no matter what language they code in.

This topic is now closed to further replies.
  • Posts

    • Markdown's creator weighs in on rumored Apple Notes export feature by David Uzondu The rumor mill is churning as we draw closer to WWDC2025, and one of the interesting developments being discussed is a report from 9To5Mac that claimed Apple Notes in iOS 19 iOS 26, will finally get Markdown export capabilities. This caught the attention of many, including the person who actually invented Markdown. John Gruber, the creator of Markdown, shared his thoughts on this potential new feature on his weblog. For those who don't know, Markdown, which Gruber developed back in 2004 with significant input from Aaron Swartz (RIP!), is a lightweight markup language designed for creating formatted text using a plain text editor. Its main advantage is that it is easy to read and easy to write. When the news first broke, some interpretations suggested Apple Notes would gain full Markdown support, transforming it into an application where users could directly type and see Markdown syntax, much like how specialized editors like Obsidian operate. These tools are intended for users to work directly within the Markdown framework for all their note-taking. Gruber himself indicated that he does not believe Apple Notes should become a full-fledged "Markdown editor," even as an option. He stated that such a change would be a "huge mistake." His reasoning is rooted in his original vision for Markdown and his view of Apple Notes' purpose. He reiterated that he initially designed Markdown as a "text-to-HTML conversion tool for web writers" and for contexts requiring plain text file storage. He feels Apple Notes serves a different, valuable role with its current WYSIWYG (What You See Is What You Get) rich text editing. This interface, he argues, is excellent for quickly capturing thoughts, particularly on an iPhone, and aligns with the Macintosh philosophy of user-friendliness. He pointed out that creating a syntactically incorrect markdown is trivial, whereas a malformed note should not be possible with Apple Notes. Despite his reservations about a complete Markdown overhaul for the editing experience, Gruber finds the prospect of exporting notes in Markdown format very appealing. He wrote that this specific capability "sounds awesome." He pointed out, quite rightly, that Apple Notes' current export functions are rather limited, primarily offering PDF and Pages document formats. Adding Markdown export would provide a much more flexible way for users, especially those in the "niche" he identifies with, to move their content out of Notes and into other applications. Gruber did express curiosity about how Apple might handle images embedded in notes during a Markdown export, as image handling can be a tricky aspect of Markdown.
    • What? Every single app I've installed from the Microsoft Store comes from its intended developer and works perfectly fine. What apps do you install?
    • Microsoft Store is such a weird place filled with so much absolute garbage and with reputable apps that somehow come from questionable sources. Like, the app name is known, the images back it up but the publisher is just some weird name that's not mentioned for the apps we know.
    • NTLite 2025.06.10459 is out.
    • Wireshark 4.4.7 by Razvan Serea  Wireshark is a network packet analyzer. A network packet analyzer will try to capture network packets and tries to display that packet data as detailed as possible. You could think of a network packet analyzer as a measuring device used to examine what's going on inside a network cable, just like a voltmeter is used by an electrician to examine what's going on inside an electric cable (but at a higher level, of course). In the past, such tools were either very expensive, proprietary, or both. However, with the advent of Wireshark, all that has changed. Wireshark is perhaps one of the best open source packet analyzers available today. Deep inspection of hundreds of protocols, with more being added all the time Live capture and offline analysis Standard three-pane packet browser Multi-platform: Runs on Windows, Linux, OS X, Solaris, FreeBSD, NetBSD, and many others Captured network data can be browsed via a GUI, or via the TTY-mode TShark utility The most powerful display filters in the industry Rich VoIP analysis Read/write many different capture file formats Capture files compressed with gzip can be decompressed on the fly Live data can be read from Ethernet, IEEE 802.11, PPP/HDLC, ATM, Bluetooth, USB, Token Ring, Frame Relay, FDDI, and others (depending on your platfrom) Decryption support for many protocols, including IPsec, ISAKMP, Kerberos, SNMPv3, SSL/TLS, WEP, and WPA/WPA2 Coloring rules can be applied to the packet list for quick, intuitive analysis Output can be exported to XML, PostScript®, CSV, or plain text Wireshark 4.4.7 changelog: The following vulnerabilities have been fixed wnpa-sec-2025-02 Dissection engine crash. Issue 20509. CVE-2025-5601. The following bugs have been fixed Wireshark does not correctly decode LIN "go to sleep" in TECMP and CMP. Issue 20463. Dissector bug, Protocol CIGI. Issue 20496. Green power packets are not dissected when proto_version == ZBEE_VERSION_GREEN_POWER. Issue 20497. Packet diagrams misalign or drop bitfields. Issue 20507. Corruption when setting heuristic dissector table UI name from Lua. Issue 20523. LDAP dissector incorrectly displays filters with singleton "&" Issue 20527. WebSocket per-message compression extentions: fail to decompress server messages (from the 2nd) due to parameter handling. Issue 20531. The LL_PERIODIC_SYNC_WR_IND packet is not properly dissected (packet-btle.c) Issue 20554. Updated Protocol Support AT, BT LE LL, CIGI, genl, LDAP, LIN, Logcat Text, net_dm, netfilter, nvme, SSH, TCPCL, TLS, WebSocket, ZigBee, and ZigBee ZCL Download: Wireshark 4.4.7 | 83.2 MB (Open Source) Download: Portable Wireshark 4.4.7 | ARM64 Installer View: Wireshark Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      CHUNWEI earned a badge
      Week One Done
    • One Year In
      survivor303 earned a badge
      One Year In
    • Week One Done
      jbatch earned a badge
      Week One Done
    • First Post
      Yianis earned a badge
      First Post
    • Rookie
      GTRoberts went up a rank
      Rookie
  • Popular Contributors

    1. 1
      +primortal
      419
    2. 2
      snowy owl
      183
    3. 3
      +FloatingFatMan
      182
    4. 4
      ATLien_0
      176
    5. 5
      Xenon
      139
  • Tell a friend

    Love Neowin? Tell a friend!