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 7763231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:36:33+00:00 2026-06-01T14:36:33+00:00

I am having trouble getting a variable from one defined function to another. For

  • 0

I am having trouble getting a variable from one defined function to another.
For example, I want user to select a country from a menu and then that country to be saved in a variable for the first function.
After that, user has to select a package they want from the second menu and then tell the program how many people ages 12+, 2+ and 2- are going.

Once it is done, I want all the saved information to go to a table, for example if a user had selected Spain and full board package and there are 2 people aged 12+ and 1 people aged 2+i want the program to go to Spain table and add the prices. the prices are different for all ages.

below is the code I got so far, I was wondering if anyone could help with it.

def result():
    global spian
    global spianf
    total=spian*n+spianf
    print total

def total():
    global n
    global i
    result()

def age ():
    n=input("please select number of people age 12+")
    m=input("please select number of people age 2+ ")
    b=input("please select number of people age 2-")
    total()
    result()


def pack():
   print "1.Full Boaard"
   print "2.Half board"
   print "3.Beds only"
   print "4.Main menu"
   n=raw_input("please select you package ")
   if n=="1":
     age()
     return n;
   if n=="2":
    age()
   if n=="3":
    age()
   if n=="4":
    country()



def country ():
   print "1.Spain"
   print "2.Portugal"
   print "3.Italy"
   print "4.Turkey"
   print "5.Exit"
   i=raw_input("Please enter your choice of country ")
   if i=="1":
       pack()
       spain=1
   if i=="2":
      pack()
   if i=="3":
       pack()
   if i=="4":
       pack()
   if i=="5":
       exit

 country()
 spian=150
 spianf=50
  • 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-06-01T14:36:34+00:00Added an answer on June 1, 2026 at 2:36 pm

    If you are just starting out learning python, I would highly recommend not developing a habit like this of using globals for the variables in all of your functions.

    Take a moment to review this page from the python docs: http://docs.python.org/tutorial/controlflow.html#defining-functions

    For instance, while you could technically fix your problem in this function:

    def age ():
        global n,m,b
        n=input("please select number of people age 12+")
        m=input("please select number of people age 2+ ")
        b=input("please select number of people age 2-")
    

    … It would be much more useful for your function to return something

    def age ():
        n=input("please select number of people age 12+")
        m=input("please select number of people age 2+ ")
        b=input("please select number of people age 2-")
        return n, m, b
    
    # and call it like
    n, m, b = age()
    

    If you have a function that wants to modify your spian, you might do something like this:

    def newSpian(spianVal):
        return spianVal * 100
    
    # and call it like
    newSpianValue = newSpian(spian)
    # or overwrite the old one
    spian = newSpian(spian)
    

    This will make your functions far more reuseable, and also easier to understand. When you make use of globals for everything like this, its hard to know where a variable even comes from in the logic. You have to look through all of your other functions to figure out what might have changed it along the way, or even created its current value.

    I would also recommend you use more useful variable names than a,b,c,d

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble getting teh results i want from this mysql query. And
I'm having trouble getting a variable from a for loop. It seems i(var) is
I am having trouble getting a background-image to overlay the border of another div.
I'm having trouble getting any information to display from this query. Anyone know where
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
I’m having trouble getting a AJAX/JSON function to work correctly. I had this function
Having trouble getting my POST arrays to show all checkbox values from my form.
I am having trouble getting some data from a JSON object which I have
Having some trouble getting this query to work correctly. mysql_query(DELETE FROM `table` WHERE `id`
I am having trouble getting my class to from program.cs to run in form.cs

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.