Thursday, December 11, 2014

Use Python!

Simple Python Interpreter Online Python Interpreter

A Python Interpreter

This is a simple online Python interpreter, built using the Skulpt engine (slightly modified by kwalsh).
Put your Python code below (copy-and-paste or just type it in directly), then click run.
Note: this isn't a complete version of Python. See below.


Output:
Some caveats:
  • The raw_input("...") and input("...") functions work a little differently here than in actual Python. They bring up a dialog box as a separate window, rather than having you type responses in the same window as the output. And, you must pass a string argument to each function.
  • The input("...") function only accepts integers and floating point numbers. Normally, the Python input("...") function would accept any expression as input, such as quoted strings, variables, arithmetic operators, etc.
  • This is a very incomplete implementation of Python. There are likely bugs, and many Python features are missing. But it should work for basic arithemtic and strings, and should be sufficient for at least some simple programs.

Simple commands:
print ("[what you want to appear as text]")
variable = raw_input("[question to be answered in text to define a variable value, should be words]")
The variable may now be used like so:
name = raw_input("What's your name?")
print ("Hello, " + name + ".")

Or:
name = raw_input("What's your name?")
favfood = raw_input(name + ", what's your favorite food?")

You can use a variable value and divert it to separate uses:
if favfood == "Pasta": print ("Mine too!")
if favfood == "Gorgonzola": print ("No thanks!")

Have fun!

No comments:

Post a Comment