Python Forum
Are my descriptions (comments) correct here? [newbie needs help]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Are my descriptions (comments) correct here? [newbie needs help]
#1
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 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)
Reply


Messages In This Thread
Are my descriptions (comments) correct here? [newbie needs help] - by MattSS102 - Oct-10-2017, 04:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Algorithm for extracting comments from Python source code Pavel1982 6 585 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  How do I add comments from a text-file to an array of folders? clausneergaard 2 1,810 Feb-08-2023, 07:45 PM
Last Post: Larz60+
  Inserting line feeds and comments into a beautifulsoup string arbiel 1 1,208 Jul-20-2022, 09:05 AM
Last Post: arbiel
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,336 Dec-04-2021, 08:33 PM
Last Post: Ascalon
  Multiline comments macfanpl 6 2,787 May-07-2020, 08:14 PM
Last Post: macfanpl
  Can the comments produce errors in python? newbieAuggie2019 9 4,326 Nov-26-2019, 12:19 AM
Last Post: micseydel
  Variable comments on Visual Studio Code sal 2 3,233 Oct-19-2019, 02:13 PM
Last Post: sal
  Regular expression to fetch comments in C using Python pikkip 4 4,925 Jan-24-2017, 09:21 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020