Background
Hello is a language "written" by Anne Veling, which errors if the program does not contain only h
, and will print Hello World
for every h
Task
You are to write an interpreter/compiler for Hello.
Example in Python
import os
i = input("Program: ")
for a in i:
if a != 'h':
print("err")
quit()
else:
print("Hello World")
Details
- If the program is not only
h
s, it must printerr
orerror
(case-insensitive) - It's okay if you print "Hello World"s before your program discovers a non-
h
character and errors, however, the program must halt if a non-h
- You may throw an error, as long as you print
err
/error
before throwing, or by using a custom error builtin, likeraise SyntaxError('err')
in python. (basically, you have to purposefully error witherr
/error
- Assume the program will not be empty
- Output can have a trailing newline, space, or nothing to separate
Hello World
s - If a program has multiple lines, it should error (due to
\n
not being anh
) - You can assume that input will always be ASCII 33-126 and 10 (decimal)
- The
h
s are case sensitive (soH
is not a valid program) instruction is found - This is code-golf, shortest answer wins
Test cases
Input:
h
Output:
Hello World
Input:
hhhhhh
Output:
Hello WorldHello WorldHello WorldHello WorldHello WorldHello World
(again, it doesn't matter whether it's spaces, newlines, or nothing to separate `Hello World`s
Input:
rubbish
Output:
err
Input:
huh
Output:
Hello Worlderr
Or
err
First challenge so please have mercy
Hello World
s? \$\endgroup\$hhxhh
outputs “Hello WorldHello Worlderr”) and those which only implement the written rules (forhhxhh
outputs “err”). This is not good. Please clarify and add a relevant test case. \$\endgroup\$h
character and errors" \$\endgroup\$err
, I said it could printHello Worlderr
orerr
\$\endgroup\$