Python Forum
Please Help Understand Functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please Help Understand Functions
#1
I had an assignment that required me to perform a task using only modules. I turned in a botched version, but I would actually like to learn how to do it, since it seems important.

Goal: Get numbers from user, add one, display result; all while using modules.

# Enter numbers and store them as "enterNumbers()" module?
def enterNumbers():
    float(input("Type numbers: "))
    return

# This "calculate" module calls the "enterNumbers()" module, adds 1, and returns "a" which basically means "a" in the module IS "calculate()?"
def calculate():
    a = enterNumbers() + 1
    return a

# This "main()" module calls both module to calculate?
def main():
    enterNumbers()
    calculate()
    return

# This runs all of the modules?
main()
My code seems to duplicate "enter numbers" twice. I'm pretty sure it's because I have "enterNumbers" in the "calculate()" module, as well as the "main()" module. To me, it seems like "a" is defining "enterNumbers() + 1", so I'm not trying to call it, only use it's stored data. Also, i feel like I'm missing something in the () of one of the modules to make it work right, I just can't figure out what.

If anyone would be kind enough to walk me through my code, keeping it as close as possible to the original while using modules, that would be appreciated.
Reply


Messages In This Thread
Please Help Understand Functions - by toxicxarrow - Feb-21-2018, 08:23 PM
RE: Please Help Understand Functions - by Larz60+ - Feb-21-2018, 08:47 PM
RE: Please Help Understand Functions - by Larz60+ - Feb-21-2018, 10:06 PM
RE: Please Help Understand Functions - by nilamo - Feb-21-2018, 10:26 PM

Forum Jump:

User Panel Messages

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