Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #67505

Re: Help with "Guess the number" script

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <swdunning@cox.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'argument': 0.05; '(b)': 0.07; 'assignment': 0.07; '"("': 0.09; 'bold': 0.09; 'directions': 0.09; 'function,': 0.09; 'main()': 0.09; 'parameter': 0.09; 'subject:number': 0.09; 'subject:script': 0.09; 'cc:addr:python-list': 0.11; 'subject:Help': 0.11; 'def': 0.12; 'wrote': 0.14; 'random': 0.14; 'conditional': 0.16; 'guess.': 0.16; 'main():': 0.16; 'range,': 0.16; 'wrote:': 0.18; '&lt;': 0.19; 'received:10.0.1': 0.19; 'things.': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; '(a)': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'task': 0.26; 'second': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'statement': 0.30; 'code': 0.31; '"please': 0.31; 'anyone': 0.31; 'figure': 0.32; 'supposed': 0.32; 'thanks!': 0.32; 'option': 0.32; 'guess': 0.33; 'trouble': 0.34; '"the': 0.34; 'subject:the': 0.34; 'could': 0.34; 'subject:with': 0.35; 'add': 0.35; 'received:10.0': 0.36; 'two': 0.37; 'received:10': 0.37; 'checks': 0.38; 'pm,': 0.38; 'does': 0.39; 'subject:" ': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; 'tell': 0.60; 'new': 0.61; 'numbers': 0.61; 'range': 0.61; 'first': 0.61; 'header:Message-Id:1': 0.63; 'high': 0.63; 'kept': 0.65; 'to:addr:gmail.com': 0.65; 'charset:windows-1252': 0.65; 'within': 0.65; 'here': 0.66; 'mar': 0.68; 'hints': 0.68; 'secret': 0.74; '2014,': 0.84; 'secret.': 0.91; 'scott': 0.93; 'hot': 0.96
X-CT-Class Clean
X-CT-Score 0.00
X-CT-RefID str=0001.0A020204.5313FAB0.00C8,ss=1,re=0.000,fgs=0
X-CT-Spam 0
X-Authority-Analysis v=2.0 cv=Q4UMFfKa c=1 sm=1 a=MB85R812cvcrhCHz/P2OVA==:17 a=gK21Zm9gRZcA:10 a=G8Uczd0VNMoA:10 a=kviXuzpPAAAA:8 a=OG9Dvookndn_xi7P1l4A:9 a=pILNOxqGKmIA:10 a=4vB-4DCPJfMA:10 a=D4igxPIFR6kvQVaN:21 a=HvFza3YNJoLXut5w:21 a=Gb1Cj3n4xmhFCtSt46QA:9 a=_W_S_7VecoQA:10 a=MB85R812cvcrhCHz/P2OVA==:117
X-CM-Score 0.00
Authentication-Results cox.net; auth=pass (PLAIN) smtp.auth=swdunning@cox.net
Content-Type multipart/alternative; boundary="Apple-Mail=_1E30E07F-8F32-4BC3-A409-B3A00EA0E553"
Mime-Version 1.0 (Mac OS X Mail 7.1 \(1827\))
Subject Re: Help with "Guess the number" script
From Scott W Dunning <swdunning@cox.net>
In-Reply-To <B16295AB-B14D-4271-A9E5-71DB734B867D@cox.net>
Date Sun, 2 Mar 2014 20:44:47 -0700
References <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> <mailman.7516.1393691734.18130.python-list@python.org> <D9724003-3B31-4B30-AEFF-9AD34F581CB8@cox.net> <YRJP1n00U3bjUJS01RJQ57> <B16295AB-B14D-4271-A9E5-71DB734B867D@cox.net>
To Chris Angelico <rosuav@gmail.com>
X-Mailer Apple Mail (2.1827)
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7620.1393818297.18130.python-list@python.org> (permalink)
Lines 224
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1393818297 news.xs4all.nl 2869 [2001:888:2000:d::a6]:40533
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:67505

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Mar 2, 2014, at 6:40 PM, Scott W Dunning <swdunning@cox.net> wrote:

This is what Im having trouble with now.  Here are the directions I’m stuck on and what I have so far, I’ll bold the part that’s dealing with the instructions if anyone could help me figure out where I’m going wrong.  

Thanks!

from random import randrange
randrange(1, 101)
from random import seed
seed(129)
    
def print_description():
    print """Welcome to Guess the Number.
    I have seleted a secret number in the range 1 ... 100.
    You must guess the number within 10 tries.
    I will tell you if you ar high or low, and
    I will tell you if you are hot or cold.\n"""
   
def get_guess(guess_number):
    promt = "(" + str(guess_number) +") Please enter a guess:"
    user_guess = raw_input(promt)
    user_guess = int(user_guess)
    return user_guess

def print_hints(secrets, guess):
    secret_number = secret
    guess = guess
    if guess < 0 or user_guess> 101:
        print "Out of range!"

def main():
    print_description()
    secret = randrange(1,101)
    current_guess = get_guess(1)
    if current_guess != secret:
        print_hints(secret_number, guess)
        current_guess = get_guess(2)
        
    if secret == current_guess:
        print "Congratulations, you win!"
    else:
        print "Please play again"
    print "The secret number was", secret        
            
main()
Just below the body of the get guess function, define a new function named print hints that takes two arguments. The first is a secret num- ber and is kept in a parameter named secret. The second is a guess made by the user and it is held in a parameter named guess.

The user’s guess is supposed to be within the range 1 ... 100. Write a conditional statement that checks if the guess is out of that range, and if it is print ‘out of range’ in the body of the print hints function.

Now we are going to give the user the option to make a second guess. You must add code to the main function immediately after assignment statement you wrote for task 7.

Write a conditional statement to check if the current guess does not match the secret number. If the numbers to not match, in the body of the conditional statement you will do two things.

(a)  call print hints to give the user hints,

(b)  re-assign current guess to the result of calling get guess with an

argument of 2. 

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Help with "Guess the number" script Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-03-01 11:35 -0500
  Re: Help with "Guess the number" script Susan Aldridge <susanaldridge555@gmail.com> - 2014-03-01 10:03 -0800
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-01 18:11 -0700
    Re: Help with "Guess the number" script Larry Hudson <orgnut@yahoo.com> - 2014-03-01 23:38 -0800
    Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 18:36 -0700
  Re: Help with "Guess the number" script Chris Angelico <rosuav@gmail.com> - 2014-03-02 12:16 +1100
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 18:40 -0700
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 20:44 -0700
  Re: Help with "Guess the number" script Ben Finney <ben+python@benfinney.id.au> - 2014-03-03 14:52 +1100
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 21:04 -0700
  Re: Help with "Guess the number" script Dave Angel <davea@davea.name> - 2014-03-03 02:10 -0500

csiph-web