Well, in python I was planning to do something like this:

>> echo text
text
>>

But I just cant find a way to do it!
I know that for user input i will use input(), but how do I get it to
echo the text specified?

Edited 4 Years Ago by HTMLperson5

HTMLperson5
Deleted Member

OK, here for you start:

from __future__ import print_function
try:
    input, range = raw_input, xrange
except NameError:
    pass


def quit_():
    raise SystemExit

def plus(a, b):
    return int(a)+int(b)

commands = {'echo':print, 'quit':quit_, '+':plus}

while True:
    c = input('>>').split(None, 1)
    if len(c) == 2:
        c, args = c
        args = args.split()
    elif c:
        c, args = c[0], []

    else:
        #empty line
        continue

    try:
        _ = commands[c](*args)
        if _ is not None:
            print(_)
    except KeyError:
        print('%s is not recognized command' % c)
    except TypeError:
        print('%s given wrong parameters: %s!' % (c, ' '.join(args)))
    except SystemExit:
        print('Bye, bye')
        break
    except ValueError:
        print('Problem with values of parameters for %s: %s' % (c, ' '.join(args)))

"""Output:
>>ehco hi!
ehco is not recognized command
>>echo Hi, newbie!
Hi, newbie!
>>+ 12
+ given wrong parameters: 12!
>>+ 1 2.3
Problem with values of parameters for +: 1 2.3
>>+ 1 1
2
>>quit
Bye, bye
>>> 
"""

Edited 4 Years Ago by pyTony: Only None not printing

This article has been dead for over six months. Start a new discussion instead.