Functions

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile: Change the print statement in the function to print “Creating a spreadsheet called title with row_count rows”, where title and row_count are replaced with their respective values.

Remember, to concatenate a number to a string object, you’ll first have to cast row_count to a string using str() . Otherwise, you’ll get a TypeError . this is the step i’m on currently Preformatted text Define create_spreadsheet():

def create_spreadsheet(title,row_count=1000):

print("Creating a spreadsheet called "+title+“with”+str(row_count)+“row.”

Call create_spreadsheet() below with the required arguments:

create_spreadsheet(“Downloads”) <== this equals a syntax error I looked at the solution where did i go wrong

Hi,

Remember to format your trouble code with </> before pasting. Otherwise it can be hard to tell what went wrong.

Assuming this is your code, it could be that it’s not literal enough in regards to the required arguments. Can you copy and paste the syntax error? If you use special characters for the quotes “” that could lead to an error.

Otherwise, this code should run.

def create_spreadsheet(title,row_count=1000):
   print("Creating a spreadsheet called "+title+"with"+str(row_count)+"row."

create_spreadsheet("Downloads")
# Define create_spreadsheet():
def create_spreadsheet(title,row_count=1000):
  print("Creating a spreadsheet called "+title+"with"+str(row_count)+"row."

# Call create_spreadsheet() below with the required arguments:
create_spreadsheet("Downloads")

Change the print statement in the function to print “Creating a spreadsheet called title with row_count rows”, where title and row_count are replaced with their respective values.

Remember, to concatenate a number to a string object, you’ll first have to cast row_count to a string using str() . Otherwise, you’ll get a TypeError .

Then"Downloads" gets a syntax error

Should have seen the output Creating a spreadsheet called Downloads with 1000 rows I get this message where is my mistake

Right, if you print your message you will see what the issue is. Remember to consider spaces in strings when concatenating with +.

downloads gets a syntax error it shows me where is but thats where i’m stuck

To be a little clearer:

+title+"with"+str(row_count) will print something like MyTilewith1000

Same issue with “row”

Preformatted text def create_spreadsheet(title,row_count=1000):
print("Creating a spreadsheet called "+ “Downloads”+ “with” + str
(“1000”) this what i wrote after i reread the step but then i get this File “script.py”, line 7
create_spreadsheet()
^
SyntaxError: invalid syntax

the error is between the T and the parenthesis

You’re getting a syntax error for not closing your print parenthesis.
But the issue is also with the string concatenation…
I’ll give you an example to try to highlight the issue:

hello = "hello"
greeting = "how are you?"

print(hello + greeting)
# output:
# hellohow are you?

print(hello + " " + greeting)
# hello how are you?

print(hello + ", " + greeting)
# hello, how are you?
2 Likes

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