Reputation: 14875
That's my second post in 2 days about pyschools , i hope it's OK. The exercise asks me to do the following: Write a function that uses a default value. It also gives me an example code which i have to improve in order to print out the correct output (like if the input is introduce('Lim', 20) , the output should be 'My name is Lim. I am 20 years old.' The code given by pyschool which i have to improve:
def introduce(name, age = 0):
msg = "My name is %s. " % name
if age == 0:
msg += ""
else:
msg += ""
return msg
My code:
def introduce(name, age=0):
msg = "My name is %s. " % name
if age == 0:
msg += " My age is secret."
else:
msg += " I am %d years old." % age
return msg
It returns the same answers as pyschools' code checker, but due to unclear reasons, the website says my answers are wrong. What might be the problem ? I'm sorry if i didn't make myself clear enough and you don't understand what i'm trying to say. I have a hard time expressing myself as English is not my native language. Thank you very much!
Upvotes: 0
Views: 941
Reputation: 1
Try this one:
def introduce(name, age=0):
msg = "My name is %s. " % name
if age == 0:
msg += "My age is secret."
else:
msg += "I am %s years old." % age
return msg
Upvotes: 0
Reputation: 65791
Your code is fine. The only thing I can think of is that the output has two spaces in the middle. Try fixing that: msg = "My name is %s." % name
Upvotes: 2