Oct-10-2017, 04:55 AM
I'm curious what the name of the "slots" are that I mentioned in my comments. These are slots in the function. There are two in the parentheses in this function.
This is from an exercise in learn python the hard way.
This is from an exercise in learn python the hard way.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#This line defines the function cheese_and_crackers and it assigns two "slots" which have #distinct names that can be used by other pieces of code to correspond to the two variables #in the strings in this function. def cheese_and_crackers(cheese_count, boxes_of_crackers): #This line is the first string printed by this function and it takes the first variable in any #piece of code that calls this function. print "You have %d cheeses!" % cheese_count #This line is a string which takes input from a variable at the part where it says "%d" print "You have %d boxes of crackers!" % boxes_of_crackers #This line is another string from the function cheese_and_crackers. print "Man that's enough for a party!" #This line is a string which is the last printed element of the function cheese_and_crackers. print "get a blanket.\n" #This prints a line above the standard output from the function cheese_and_crackers. print "We can just give the function numbers directly:" #This line calls the function and inputs 20 and 30 into the respective "slots" (two of them) #in this function. Maybe these are called arguments? cheese_and_crackers( 20 , 30 ) #This line prints on top of the output from the function cheese_and_crackers when it takes the #input from "amount_of_cheese" and "amount_of_crackers" print "OR, we can use variables from our script:" #This line defines the variable "amount_of_cheese" as 10 amount_of_cheese = 10 #this line defines the variable amount_of_crackers as 50 amount_of_crackers = 50 #This line takes the variables amount_of_cheese and amount_of_crackers and plugs them into the #function cheese_and_crackers defined at the start cheese_and_crackers(amount_of_cheese,amount_of_crackers) #This line prints a "new" statement above the output of cheese_and_crackers function output print "We can even do math inside too:" #This line calls the function cheese and crackers from the top and it inserts the value of the #combined numbers and uses each as a variable as seen in the defined function's 2 variable set up #Then each value is printed in the designated spot in the function cheese_and_crackers cheese_and_crackers( 10 + 20 , 5 + 6 ) #This line prints a "new" statement above the output of cheese_and_crackers function output print "And we can combine the two, variables and math:" #This line calls the function cheese and crackers from the top and it inserts the value of the #variables in the parentheses and combines them with the numbers seen next to them and it plugs #the result into the strings (and variables) stipulated in the function cheese_and_crackers cheese_and_crackers(amount_of_cheese + 100 , amount_of_crackers + 1000 ) |