Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function Help
#3
(Nov-26-2016, 05:12 AM)Millionsunz Wrote: What I don't seem to understand is why the function needs no arguments
Because all input and calculation is inside the the function block.
(Nov-26-2016, 05:12 AM)Millionsunz Wrote: when I put in an argument, like arg1, I can put in a random value.
You can put in whatever you want because you do not use argument in function.
Now is argument been used in function,and return total + argument(arg1).
def testadditon(arg1): 
    fingers = input("How many fingers do you have?")
    toes = input("How many toes do you have?")
    total = fingers + toes
    return total + arg1 # Aliens has more fingers

alien_fingers = 100
total = testadditon(alien_fingers) # to easily show what I mean
print(total)
To spilt it up so you see that one function is only returting,
and the other function to calculation.
def body_parts():
    fingers = int(raw_input("How many fingers do you have?"))
    toes = int(raw_input("How many toes do you have?"))
    return fingers, toes

def body_calc(body_parts):
    fingers, toes =  body_parts()
    total = fingers + toes
    return total

if __name__ == '__main__':    
    print body_calc(body_parts)
As a new user you should be thinking of using Python 3.
Then you don't need to think of int(raw_input()),because input() is not safe(python 2.x).
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