See below for comments. On Wed, Mar 28, 2018 at 4:18 AM, Aivar Annamaa <aivar.annamaa@ut.ee> wrote:
Hi! Let's say my students are able to write programs like this:
name = input("name")
if name == "Pete": greeting = "Hi" else: greeting = "Hello!"
print(f""" <html> <body> {greeting} {name}! </body> </html> """)
I'd like to allow them start writing web-apps without introducing functions first (most web-frameworks require functions).
input() and print() *are* functions. And they are not even the simplest possible functions as they require arguments. Since input and print are not normally used that way in web apps, I would use the appropriate functions from a web framework.
It occurred to me that it's not hard to create a wrapper, which presents this code as a web-app (input would be patched to look up GET or POST parameters with given name).
Python's input() function is something that interactively prompts the user for input, generally asking a question and expecting the user to enter an answer. If you patch it to use a GET or POST, you transform it into something that is no longer interactive, but passively read from some other source. Brython (a web-based Python implementation) uses a javascript prompt() as a hook for Python's input - thus reproducing the intent of the input() function.
This approach would allow simple debugging of the code on local machine and no extra libraries are required in this phase.
Any opinions on this?
My first impression is that wanting to have students write web apps as their introduction to Python is needlessly complicating things for them as it tries to do too much all at once. My preferred approach is based on Pattis's Karel the robot which *starts* with simple functions, requiring no arguments, and build from there. (See http://reeborg.ca/reeborg.html for an example; tutorial at http://reeborg.ca/docs/en/.)
Has this been tried before?
Not that I aware of. Best of luck, André
best regards, Aivar
_______________________________________________ Edu-sig mailing list Edu-sig@python.org https://mail.python.org/mailman/listinfo/edu-sig