def thank_you(name): # This function prints a two-line personalized thank you message. print("\nYou are doing good work, %s!" % name) print("Thank you very much for your efforts on this project.") thank_you('Adriana') thank_you('Billy') thank_you('Caroline') ###highlight=[10] def thank_you(name): # This function prints a two-line personalized thank you message. print("\nYou are doing good work, %s!" % name) print("Thank you very much for your efforts on this project.") thank_you('Adriana') thank_you('Billy') thank_you('Caroline') thank_you() ###highlight=[2,3,4,5] def thank_you(name='everyone'): # This function prints a two-line personalized thank you message. # If no name is passed in, it prints a general thank you message # to everyone. print("\nYou are doing good work, %s!" % name) print("Thank you very much for your efforts on this project.") thank_you('Adriana') thank_you('Billy') thank_you('Caroline') thank_you() def describe_person(first_name, last_name, age): # This function takes in a person's first and last name, # and their age. # It then prints this information out in a simple format. print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) print("Age: %d\n" % age) describe_person('brian', 'kernighan', 71) describe_person('ken', 'thompson', 70) describe_person('adele', 'goldberg', 68) ###highlight=[10,11,12] def describe_person(first_name, last_name, age): # This function takes in a person's first and last name, # and their age. # It then prints this information out in a simple format. print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) print("Age: %d\n" % age) describe_person(71, 'brian', 'kernighan') describe_person(70, 'ken', 'thompson') describe_person(68, 'adele', 'goldberg') def describe_person(first_name, last_name, age): # This function takes in a person's first and last name, # and their age. # It then prints this information out in a simple format. print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) print("Age: %d\n" % age) describe_person(age=71, first_name='brian', last_name='kernighan') describe_person(age=70, first_name='ken', last_name='thompson') describe_person(age=68, first_name='adele', last_name='goldberg') def describe_person(first_name, last_name, age, favorite_language): # This function takes in a person's first and last name, # their age, and their favorite language. # It then prints this information out in a simple format. print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) print("Age: %d" % age) print("Favorite language: %s\n" % favorite_language) describe_person('brian', 'kernighan', 71, 'C') describe_person('ken', 'thompson', 70, 'Go') describe_person('adele', 'goldberg', 68, 'Smalltalk') ###highlight=[2,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26] def describe_person(first_name, last_name, age=None, favorite_language=None, died=None): # This function takes in a person's first and last name, # their age, and their favorite language. # It then prints this information out in a simple format. # Required information: print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) # Optional information: if age: print("Age: %d" % age) if favorite_language: print("Favorite language: %s" % favorite_language) if died: print("Died: %d" % died) # Blank line at end. print("\n") describe_person('brian', 'kernighan', favorite_language='C') describe_person('ken', 'thompson', age=70) describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk') describe_person('dennis', 'ritchie', favorite_language='C', died=2011) describe_person('guido', 'van rossum', favorite_language='Python') def adder(num_1, num_2): # This function adds two numbers together, and prints the sum. sum = num_1 + num_2 print("The sum of your numbers is %d." % sum) # Let's add some numbers. adder(1, 2) adder(-1, 2) adder(1, -2) ###highlight=[8] def adder(num_1, num_2): # This function adds two numbers together, and prints the sum. sum = num_1 + num_2 print("The sum of your numbers is %d." % sum) # Let's add some numbers. adder(1, 2, 3) def example_function(arg_1, arg_2, *arg_3): # Let's look at the argument values. print('\narg_1:', arg_1) print('arg_2:', arg_2) print('arg_3:', arg_3) example_function(1, 2) example_function(1, 2, 3) example_function(1, 2, 3, 4) example_function(1, 2, 3, 4, 5) ###highlight=[6,7] def example_function(arg_1, arg_2, *arg_3): # Let's look at the argument values. print('\narg_1:', arg_1) print('arg_2:', arg_2) for value in arg_3: print('arg_3 value:', value) example_function(1, 2) example_function(1, 2, 3) example_function(1, 2, 3, 4) example_function(1, 2, 3, 4, 5) def adder(num_1, num_2, *nums): # This function adds the given numbers together, # and prints the sum. # Start by adding the first two numbers, which # will always be present. sum = num_1 + num_2 # Then add any other numbers that were sent. for num in nums: sum = sum + num # Print the results. print("The sum of your numbers is %d." % sum) # Let's add some numbers. adder(1, 2, 3) ###highlight=[19,20,21,22] def adder(num_1, num_2, *nums): # This function adds the given numbers together, # and prints the sum. # Start by adding the first two numbers, which # will always be present. sum = num_1 + num_2 # Then add any other numbers that were sent. for num in nums: sum = sum + num # Print the results. print("The sum of your numbers is %d." % sum) # Let's add some numbers. adder(1, 2) adder(1, 2, 3) adder(1, 2, 3, 4) adder(1, 2, 3, 4, 5) def example_function(arg_1, arg_2, **kwargs): # Let's look at the argument values. print('\narg_1:', arg_1) print('arg_2:', arg_2) print('arg_3:', kwargs) example_function('a', 'b') example_function('a', 'b', value_3='c') example_function('a', 'b', value_3='c', value_4='d') example_function('a', 'b', value_3='c', value_4='d', value_5='e') ###highlight=[6,7] def example_function(arg_1, arg_2, **kwargs): # Let's look at the argument values. print('\narg_1:', arg_1) print('arg_2:', arg_2) for key, value in kwargs.items(): print('arg_3 value:', value) example_function('a', 'b') example_function('a', 'b', value_3='c') example_function('a', 'b', value_3='c', value_4='d') example_function('a', 'b', value_3='c', value_4='d', value_5='e') def describe_person(first_name, last_name, age=None, favorite_language=None, died=None): # This function takes in a person's first and last name, # their age, and their favorite language. # It then prints this information out in a simple format. # Required information: print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) # Optional information: if age: print("Age: %d" % age) if favorite_language: print("Favorite language: %s" % favorite_language) if died: print("Died: %d" % died) # Blank line at end. print("\n") describe_person('brian', 'kernighan', favorite_language='C') describe_person('ken', 'thompson', age=70) describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk') describe_person('dennis', 'ritchie', favorite_language='C', died=2011) describe_person('guido', 'van rossum', favorite_language='Python') ###highlight=[2,3,4,10,11,12] def describe_person(first_name, last_name, **kwargs): # This function takes in a person's first and last name, # and then an arbitrary number of keyword arguments. # Required information: print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) # Optional information: for key in kwargs: print("%s: %s" % (key.title(), kwargs[key])) # Blank line at end. print("\n") describe_person('brian', 'kernighan', favorite_language='C') describe_person('ken', 'thompson', age=70) describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk') describe_person('dennis', 'ritchie', favorite_language='C', died=2011) describe_person('guido', 'van rossum', favorite_language='Python') ###highlight=[12,17,18,19,20,21] def describe_person(first_name, last_name, **kwargs): # This function takes in a person's first and last name, # and then an arbitrary number of keyword arguments. # Required information: print("First name: %s" % first_name.title()) print("Last name: %s" % last_name.title()) # Optional information: for key in kwargs: print("%s: %s" % (key.title().replace('_', ' '), kwargs[key])) # Blank line at end. print("\n") describe_person('brian', 'kernighan', favorite_language='C', famous_book='The C Programming Language') describe_person('ken', 'thompson', age=70, alma_mater='UC Berkeley') describe_person('adele', 'goldberg', age=68, favorite_language='Smalltalk') describe_person('dennis', 'ritchie', favorite_language='C', died=2011, famous_book='The C Programming Language') describe_person('guido', 'van rossum', favorite_language='Python', company='Dropbox')