There is always syntax error occurs


#1

print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input("Enter a word:")
def verifier(original):
  if len(original) > 0:
    return print(original)
  else:
    return print("empty")

File “python”, line 7
return print(original)
^
SyntaxError: invalid syntax

May I ask why my codes are wrong?


#2

you can’t have return and print on the same line. Python can do a lot, but that is even too much for python.


#3

Yes Yes!Thank you for your quick reply. May I ask that why I cannot put len(original) as an variable?
like this:def verifier(len(original)) ?


#4

Hi,I have another question here, I figured out why I put “return” there :
The original variable (" tony") had more than 0 characters but did not get printed.

if I delete ’ return ’ and run ,it shows this, whatever I type , the interpreter seems stuck and stops working.


#5

def keyword creates a function, you can’t you can’t convert the parameter (original) to length when defining the parameter

functions only execute when called. Why did you even include a function? Doing more then the exercise asks of you, can cause problems

it shows what?


#6

I mean It shows the error message, ah its my bad,I want to grab every chance I got to practice what I learned in school,probably it is not the right time.Most importantly,Thanks,I never get such help online.


#7

The problem is that adding additional code could sometimes produces errors (depending on how much and what kind of code you add)

And, in programming, why you do something is very important. You can indeed attempt to improve pyglatin program, but then i would ask for feedback on the forum. This feedback will get better if you can “defend” the choices you made, and why they make the program better


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.