0

I've just started learning Python. I have a little bit of experience with perl, and coming to terms with a language that seems to rely on indentations, and no termination characters.

I started small with code in Google python course:

import sys
def repeat(s, exclaim):
    result=s*3
    if exclaim:
        result=result+'!!!'
    return result
def main():
    print repeat('Yay', true)
if __name__=='__main__':
    main()

Error:

C:\python>py repeat.py
  File "repeat.py", line 8
    print repeat('Yay', true)
               ^
SyntaxError: invalid syntax     

Could anyone help me by telling me what's wrong with the code?

Joel G Mathew
  • 7,561
  • 15
  • 54
  • 86
  • Why are there two arguments in print function call? – Vikas Ojha Jun 13 '15 at 08:05
  • As far as I can understand, there aren't. The two arguments are to the repeat function. – Joel G Mathew Jun 13 '15 at 08:07
  • 2
    In python3 `print()` is valid not just `print` and use `True` not `true` – Ajay Jun 13 '15 at 08:08
  • 1
    `print` is a bit weird in Python 2 and in Perl, but that's fixed when you upgrade to Python 3. In Python 3 `print` is a *function*, which means you must supply the parentheses. In Python the parentheses are mandatory for all function calls (unlike Perl and Ruby). Also, In Python 2 `True` (not "true") is not a reserved word, but in Python 3 it is. – cdarke Jun 13 '15 at 08:49

0 Answers0