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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:26:01+00:00 2026-06-02T02:26:01+00:00

Newbie to python and hit a snag in my latest program. Simply put, I’m

  • 0

Newbie to python and hit a snag in my latest program. Simply put, I’m trying to code up a decrement loop for a user input variable if possible. Essentially I have a global constant set to value e.g. 13, each time the program loops it prompts the user to input a value then that user value is shaved off 13 until it reaches 0. Problem is that it does shave it off but when it reiterates it resets the value to 13 and only removes the current iterate value entered. So if you enter 2 each iteration it just takes it down to 11… But I’m aiming for a result using 2 as an example again, 11, 8, 5, etc etc or using 3 as an example 10, 7, 4…. Any help guys will be much appreciated, cheers 🙂

a = 13

def main():
    runLoop()

def runLoop():
    while other_input_var > 0: # guys this is my main score accumulator
                               # variable and works fine just the one below
        b=int(input('Please enter a number to remove from 13: '))
        if b != 0:
            shave(a, b)

def shave(a, b):
    a -= b
    print 'score is %d ' % a
    if a == 0:
        print "Win"

main()
  • 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-02T02:26:04+00:00Added an answer on June 2, 2026 at 2:26 am

    Not an answer to your question, but rather a demonstration of string formatting. This is the old style, using the % “string interpolation operator”.

    a = 100
    while a:
        shave = int(raw_input("Input a number to subtract from %i:" % a))
        if ( shave > 0 ) and ( shave <= a ):
            a -= shave
        else:
            print ("Number needs to be positive and less than %i." % a)
    

    A session with this program:

    Input a number to subtract from 100:50
    Input a number to subtract from 50:100
    Number needs to be positive and less than 50.
    Input a number to subtract from 50:30
    Input a number to subtract from 20:20
    

    The %i in the original string is a placeholder for an integer (i for integer) which is filled in later by the % operator on the string.

    There’s also %f for floating-point numbers, %s for strings, and so on. You can do nifty things like specify how many decimal points numbers should print with – %.3f for three decimal places – and so on.

    Another example:

    >>> "My name is %s and I'm %.2f metres tall." % ('Li-aung',1.83211)
    "My name is Li-aung and I'm 1.83 metres tall."
    

    This is a lot easier to read than:

    "My name is " + name + " and I'm " + str(round(age,2)) + " metres tall"
    

    Read up more about string formatting the old way or the new way.

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

Sidebar

Related Questions

I am a newbie on python. I have just create a program taking a
Im a newbie to python , and I came across this particular code snippet
I am a newbie to python, and just few days back I started trying
I'm newbie in Python. I can't understand why this code does not work: reOptions
python newbie here. I'm writing the code to control an experiment that has multiple
I'm a Python newbie, so I'm sure this is easy. Here's the code in
I'm newbie in Python, but this question is not a homework (actually this code
I am a newbie in Python. I can understand what a for loop does,
I am a newbie to Python and trying out different ways to optimize and
i'm python newbie, and member variable of class works weird in my python code.

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.