Your First Program
The typical first program to be written by most beginning programmers is one that simply outputs "Hello, world!" to standard output. Standard output is simply your monitor (or the screen of whatever device it is you are currently using).To make things slightly more interesting, we will write a program that writes "Hello, Dungeon!" to standard output instead.
In Python, this is pretty easy. We simply use the built-in function print() like so:
Simply click the green play button (looks like a rightward-facing triangle like the play buttons on most media players).
Notice that the top portion of the repl widget is the area dedicated to writing your code. The bottom portion shows the output that would be sent to standard output.
One of the nice things about these repl widgets is that they allow you (yes, you) to modify the code in the coding section and click play to see how the output changes accodingly!
Go ahead a play around with the code. Try misspelling print and see how that affects the output. Try changing "Hello, Dungeon!" to the classic "Hello, World!".
- How would you change the above code so that "Hello, Dungeon Master!" would be sent to standard output?
- What message is sent to standard output if you change print("Hello, Dungeon!") to pirnt("Hello, Dungeon!")?
- What message is sent to standard output if you leave out the quotation marks surrounding Hello, Dungeon!? In other words, what happens if you run print(Hello, Dungeon!)?
- What message is sent to standard output if you replace the parentheses with spaces: print "Hello, Dungeon!" .
- What happens if you just leave off the last parentheses: print("Hello, Dungeon!" ?
Join the Dungeon Crawl: A place for programmers to ponder, partake, and peruse postulations pertaining to programming, politics, potions, and pizza.
If you subscribe on Patreon, you will be granted access to the Dojo, a growing collection of quality computer science classes created and actively mantained and frequented by the Dungeon Master!Become a Patron!