Python Forum
Calling a function from another function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling a function from another function
#1
Having trouble with this one.
The problem reads below:

You will need to write two functions for this problem. The first function, "divide" that takes in any number and returns that same number divided by 2. The second function called "sum" should take any number, divide it by 2, and add 6. It should return this new number. You should call the divide function within the sum function. Do not worry about decimals.

Here's my attempt:
def divide (div):
    d2 = div/2
    print(d2)
    return d2
divide(10)

def sum (num):
    s1 = divide(num)
    s2 = s1 + 6
    print(s2)
    return s2

num = 12
Here's the output:
Output:
5.0
It seems to execute "divide" but not "sum".
Not quite sure why.
Reply


Messages In This Thread
Calling a function from another function - by johneven - Jul-09-2019, 12:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 3,486 Oct-05-2020, 07:47 PM
Last Post: deanhystad
  Passing a function to another function yulfmd1802 3 3,063 Jan-23-2020, 09:13 AM
Last Post: ndc85430
  Adding a sqrt function syntax error and <build-in function sqrt> from tkinter import Kael 0 2,382 Oct-14-2019, 05:51 PM
Last Post: Kael
  Need of return in function if statement inside the function already returns Athul 5 4,978 Aug-16-2018, 10:19 AM
Last Post: DuaneJack
  Calling function-- how to call simply return value, not whole process juliabrushett 2 4,005 Jul-01-2018, 01:17 AM
Last Post: juliabrushett
  Calling a Returned Value to Another Function valerydolce 9 8,301 Mar-28-2017, 09:54 PM
Last Post: valerydolce
  Calling a function to return a list of percentages Liquid_Ocelot 7 7,833 Mar-25-2017, 01:20 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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