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

  • Home
  • SEARCH
  • 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 8412153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:36:15+00:00 2026-06-10T00:36:15+00:00

def complex(): answer = raw_input(Would you like to run this program?) answer = answer.lower()

  • 0
def complex():
    answer = raw_input("Would you like to run this program?")

    answer = answer.lower()

    money = 5

    if "yes" in answer:
        print money
        money = money - 1
        complex()

    else:
        quit()

complex()

For some reason, every-time I enter “yes” into the raw_input it spits out 5. But I want it to spit out 5 then when I type yes again I want it to spit out 4, and then if I type yes again I want it to spit out 3….

I fixed this by using the Global statement:

money = 5
def complex():
answer = raw_input("Would you like to run this program?")
answer = answer.lower()


    if "yes" in answer:
        global money
        print money
        money = money - 1
        complex()

    else:
        quit()

complex()
  • 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-10T00:36:16+00:00Added an answer on June 10, 2026 at 12:36 am

    This is what your procedure is doing :

    1. Get user input
    2. Set variable money to 5
    3. Validate if user input value is “yes” and if so print value if variable money which is 5.
    4. Set variable money to 5 – 1 = 4
    5. Run procedure complex()
    6. Get user input
    7. Set variable money to 5
    8. Validate if user input value is “yes” and if so print value if variable money which is 5.
    9. Set variable money to 5 – 1 = 4
    10. Run procedure complex()

    …
    etc.

    As you can see your procedure is overwriting the desired value (4) with the value of 5 with each iteration that that is why it is not working as you desire.

    What you could do is make a loop to run x number of times after money has been set to five.

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

Sidebar

Related Questions

def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
I would like to render a complex type, using the JSON render method in
Let's say I have something like this: def find_the_best(array) temp = 15435435435 # sufficiently
I know normally you can use pagination like this: class SearchController < ApplicationController def
def myFunc( a, b ): def innerFunc( c ): print c innerFunc( 2 )
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def test_method [a, b, c].map {|i| yield(i) } end If I call test_method like
def any? if block_given? method_missing(:any?) { |*block_args| yield(*block_args) } else !empty? end end In
To store a complex object to Datastore i'm currently using this approach: class PickleProperty(db.Property):
class Complex: realpart,imagpart=0,0 def __init__(self): self.r = Complex.realpart self.i = Complex.imagpart x = Complex()

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.