Click here to Skip to main content
15,939,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
a = input("say 'hi'")
def toyou()
	return a + "to you too"
print(toyou)
print(toyou + !)


I get an "invalid syntax" error.

What i want to happen is it to take the input and add "to you". Then i print that the first time, then the second an a "!" to the end.

Thank you
Posted

1 solution

From the first glance I immediately see: lack of ':'. Next bug: lack of round brackets at the function call. Another one: lack of quotation marks in "!".

Must be:
a = input("say 'hi' ")
def toyou()
    return a + " to you too"
print toyou()
print toyou() + "!"


One general problem: string concatenation requires the variable a to be assigned to string. If the user input 12, toyou() will fail. It requires the user to input string literal with quotation marks; "12" would work as well as "hi". Also, pay attention: I added couple of extra blank space character to improve input prompt and output of concatenation; you would concatenate input "hi" with "to you too" resulting in "hito you too".

Another problem is using a variable a from the context outside of the function. You should better use a parameter:

def toyou(someValue)
    return someValue + " to you too"

a = input("say 'hi' ")
print toyou(a)
print toyou(a) + "!"


I tested the code fragments before posting.

Look, I'm helping you for the 2nd time with nearly the same question (thank you for accepting my previous solution, by the way). Maybe you need to improve your method of work/learning: pay more attention for the previous answers, read documentation first and do it more thoroughly, pay more attention of every small detail. Your problems are very easy; get to the speed.

Hope it will help you.

—SA
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900