Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function Help
#1
Hello Python Forums,

I am currently learning how to code in the wonderful language of Python. I am very beginner at computer programming (Python is my first language), so please let me know if the error I am making is super simple. I tired to make a very simple yet fun program just to demonstrate my ability to program a function and properly call it, as functions are my latest advent in Python. However, I seem to be a little lost. My code is down below.

maxFingers = 10
maxToes = 10
inputheight = input("What is your height in inches?")

def testaddition(): # here is part of my confusion
    fingers = input("How many fingers do you have?")
    toes = input("How many toes do you have?")
    total = fingers + toes
    return total

total = testaddition() # here is the second part of my confusion
print "You have", total, "miniature appendages."

numnails = lambda arg1, arg2: arg1 ** arg2 
print "You have", numnails(total, inputheight), "cells on your appendages."
This function is in no way mathematically correct (in the way that your height affect the number of nails you have), but it works as a tool for learning and practice. My issue is in the defining of the function. I can define it as it is up there; 
def testaddition()
And call it like it is above;
total = testaddition()
And the program will run just fine. What I don't seem to understand is why the function needs no arguments, or, when I put in an argument, like arg1, I can put in a random value. Here is a complete example of what I mean.
maxFingers = 10
maxToes = 10
inputheight = input("What is your height in inches?")

def testadditon(arg1): # to easily show what I mean
    fingers = input("How many fingers do you have?")
    toes = input("How many toes do you have?")
    total = fingers + toes
    return total

total = testadditon(0) # to easily show what I mean
print "You have", total, "miniature appendages."

numnails = lambda arg1, arg2: arg1 ** arg2 
print "You have", numnails(total, inputheight), "cells on your appendages."
The program will run the exact same. I would just like to understand why the number of arguments does not matter when I run the program. Thank you for any help you can give me.
Reply


Messages In This Thread
Function Help - by Millionsunz - Nov-26-2016, 05:12 AM
RE: Function Help - by metulburr - Nov-26-2016, 05:20 AM
RE: Function Help - by snippsat - Nov-26-2016, 08:42 PM
RE: Function Help - by wavic - Nov-27-2016, 05:12 AM
RE: Function Help - by snippsat - Nov-27-2016, 08:43 AM

Forum Jump:

User Panel Messages

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