Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7533589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:46:05+00:00 2026-05-30T05:46:05+00:00

So first let me say that I am a novice at Python and functions

  • 0

So first let me say that I am a novice at Python and functions seem to be out of my comprehension for the moment but where I am having trouble is having 3 functions be able to call each other. Here is my code(yes I know it is terribly wrong but you should see where I am going):

def menu():
    count=gearboxes
    cost=subtotal
    return subtotal


def quantity():

    gearboxes=raw_input("How many gearboxes would you like to order? ")

    return menu()



def subtotal(cost):
    if (gearboxes<=10):
        cost=gearboxes*100.0
        print cost
    elif (gearboxes>10 and gearboxes<20):
        cost=(gearboxes-10)*80.0+1000.0
        print cost
    elif (gearboxes>20):
        cost=(gearboxes-20)*70.0+1000.0+800.0
        print cost
    else:
        print "wtf m8"

    return menu()

def summary():
    print "="*80
    print "%60s %20f %20f" % ("motors",count,cost)
    print "="*80


print quantity()
print subtotal(menu)
print summary(menu)

There is it and any help would be greatly appreciated if you could explain also kind of how functions call on each other.

Thanks!

fixed version(still working)

    def quantity():
        motors=raw_input("How many motors would you like to order? ")
        gearboxes=raw_input("How many gearboxes would you like to order? ")
        sensors=raw_input("How many sensor boards would you like to order? ")

        return int(motors),int(gearboxes),int(sensors)



   def subtotal(motors,gearboxes,sensors):

        if motors<=10 and gearboxes<=15:
            motorCost=motors*100
            gearboxCost=gearboxes*50
            sensorCost=sensors*66
            return motorCost, gearboxCost, sensorCost

        if motors>10 and motors<=20 and gearboxes>15 and gearboxes<=30:
            motorCost=(motors-10)*80+1000
            gearboxCost=(gearboxes-15)*40+750
            sensorCost=sensors*66
            return motorCost, gearboxCost, sensorCost

        elif motors>20 and gearboxes>30:
            motorCost=(motors-20)*70+1000+800
            gearboxCost=(gearboxes-30)*30+750+600
            sensorCost=sensors*66
            return motorCost, gearboxCost, sensorCost

    def summary(motors,gearboxes,sensors,motorCost,gearboxCost,sensorCost):
        print "="*80
        print "%60s %20d %20d" % ("motors",motors,motorCost)
        print "%60s %20d %20d" % ("gearboxes",gearboxes,gearboxCost)
        print "%60s %20d %20d" % ("sensor boards",sensors,sensorCost)
        print "="*80


   def menu():

        a,b,c=quantity()
        d,e,f=subtotal(a,b,c)
        summary(a,b,c,d,e,f)
        return


    menu()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:46:06+00:00Added an answer on May 30, 2026 at 5:46 am

    I made some changes to your code. Treat a function like a question. When you call the function; you’re asking the question. What you pass to return is the answer to the question. So when someone asks for the subtotal of some number of gearboxes; we return cost, whatever that may be.

    We can then store the return values (the answers) in variables and use them later. For example, to pass to another function. Try to follow how information flows through the program.

    def quantity():
        count=raw_input("How many gearboxes would you like to order? ")
        return int(count)
    
    
    
    def subtotal(count):
        if count<=10:
            cost=count*100.0
            return cost
        elif count>10 and count<20:
            cost=(count-10)*80.0+1000.0
            return cost
        elif count>20:
            cost=(count-20)*70.0+1000.0+800.0
            return cost
    
    def summary(count, cost):
        print "="*80
        print "%60s %20f %20f" % ("motors",count,cost)
        print "="*80
    
    def menu():
        items = quantity()
        sub = subtotal(items)
        summary(items, sub)
    
    if __name__ == '__main__':
        menu()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, let me say that I'm a complete beginner at Python. I've never learned
Hi there First of all just let me say that I'm new in Python
Let me first say that I have quite a lot of Java experience, but
I have a question, but let me first say that this is being performed
First let me say that I really feel directionless on this question. I am
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
Let's say I have a form that collects a first name and a last
Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2},
First, we create classes that represent db entities, ok, done. Let's say we use
First let me say that I know it's better to use the subprocess module,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.