Funtion issue


#1

Hi there, I need help please. Im doing an exercise about funtions but i don’t understand what’s going on. Here i will show my code and what they are requiring.

my code:

def create_spreadsheet(title):
  
  print ('creating a spreadsheet called' + 'title'+ '.')
  
  
  create_spreadsheet (title = "Downloads")

requirement:

1.

Define a function called create_spreadsheet() that takes one argument, title , and only prints the string "Creating a spreadsheet called [TITLE]" , where [TITLE] is replaced with the value of title .

2.

Call create_spreadsheet , with a title of "Downloads" .

thank you for your advices :slight_smile:


#2

the function call is nested inside the function, why?


#3

Hi Stetim94. thank you i realized the problem. may i ask u another issue i got regarding this activity please?

i wrote this:

def calculate_age(current_year, birth_year):
  age = current_year - birth_year
  return age

my_age=calculate_age (2018,1993)
dads_age=calculate_age(2018,1954)
print ("I am" + str(my_age) "years old and my dad is" + str(dads_age) "years old")

but I’m getting this msg:

File "script.py", line 7
    print ("I am" + str(my_age) "years old and my dad is" + str(dads_age) "years old")
                                                        ^

SyntaxError: invalid syntax

why is this happening? thank you


#4

to insert a variable into a string, there should be a plus sign before and after the variable


#5

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