User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 401,613 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,709 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.

Starting Python

Join Date: Jul 2005
Location: France
Posts: 980
Reputation: bumsfeld is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 43
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Posting Shark

Re: Starting Python

  #49  
Feb 18th, 2006
This was part of a game, I modified slightly the code. The code checks that input is correct and within a supplied range.
def checkInput(type_string, present_value, low, high):
    '''uses a while loop, loops until an acceptible answer is given, then returns it'''
    prompt = "Present %s is %d, enter a new value (%d-%d): " % (type_string, present_value, low, high)
    while True: 
       try:
          a = int(raw_input(prompt))
          if low <= a <= high:
             return a
       except ValueError:
          print "Enter an integer number, please!"


# modify the present strength of 10 within the range (1-18)
modified_strength = checkInput("strength", 10, 1, 18)
print modified_strength
Reply With Quote  
All times are GMT -4. The time now is 5:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC