Python Forum
Trouble with LPtHW exercise 21
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with LPtHW exercise 21
#4
(Sep-09-2017, 01:16 PM)ichabod801 Wrote: The def statement is where the functions are defined. For age = add(30, 5) you say it's defined but not called. But it is called. That's how you call the add function: with parameters in parentheses. That causes the add function to print it's message, and the return value is stored in age. Then that age variable is used in the print statement using the results. The % operator for strings allows for inserting values into strings. The first %d in the string is replaced by the first value in the tuple. The 'd' in '%d' indicates the format (digits). Then the second %d is replaced by the second value in the tuple, and so on.

Thank you for your answers. So for my understanding:

When the arguments in the parentheses is called in the stand alone print line:

print "Age: %d, Height: %d, Weight: %d, IQ: %d" % (age, height, weight, iq) <-- stand alone print line

Lets say "age" variable is called it first prints its own line outside the stand alone print line (<-- this was causing me problems). "ADDING 30 + 5" then puts the result (return) in the print age, weight, height & iq stand alone line.

Then it moves on to the next argument in the stand alone print line and does the same.
Reply


Messages In This Thread
Trouble with LPtHW exercise 21 - by pyth31 - Sep-09-2017, 12:12 PM
RE: Trouble with LPtHW exercise 21 - by snippsat - Sep-09-2017, 12:28 PM
RE: Trouble with LPtHW exercise 21 - by ichabod801 - Sep-09-2017, 01:16 PM
RE: Trouble with LPtHW exercise 21 - by pyth31 - Sep-09-2017, 02:52 PM
RE: Trouble with LPtHW exercise 21 - by ichabod801 - Sep-09-2017, 04:50 PM
RE: Trouble with LPtHW exercise 21 - by pyth31 - Sep-09-2017, 07:46 PM
RE: Trouble with LPtHW exercise 21 - by Larz60+ - Sep-09-2017, 06:12 PM

Forum Jump:

User Panel Messages

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